--- nono/m680x0/testacc.cpp 2026/04/29 17:05:30 1.1.1.7 +++ nono/m680x0/testacc.cpp 2026/04/29 17:05:57 1.1.1.8 @@ -6,6 +6,7 @@ #include "mpu680x0.h" #include "m680x0acc.h" +#include "stopwatch.h" #include #include @@ -21,7 +22,7 @@ static int total_errcnt; // 総エラ static int errcnt; // 現在のセクションのエラー数 static char where[256]; // エラー発生箇所 static volatile int perf_signaled; // パフォーマンス測定用 -static struct timeval perf_start; // パフォーマンス測定開始時刻 +static Stopwatch sw; // パフォーマンス測定用 static uint64 perf_count; // パフォーマンス測定用。処理回数 // value を16進数で指定のビット数分の文字列にする @@ -215,19 +216,16 @@ start_perf_func(const char *name) struct itimerval it = {}; it.it_value.tv_sec = PERF_SEC; - gettimeofday(&perf_start, NULL); + sw.Restart(); setitimer(ITIMER_REAL, &it, NULL); } static void end_perf_func() { - struct timeval end, result; + sw.Stop(); - gettimeofday(&end, NULL); - timersub(&end, &perf_start, &result); - - uint64 usec = (uint64)result.tv_sec * 1000000 + (uint64)result.tv_usec; + uint64 usec = nsec_to_usec(sw.Elapsed_nsec()); printf("%" PRIu64 " times/usec\n", perf_count / usec); }