/** * @file PerfCnt.h * @brief パフォーマンスカウンタ. * @author tenk* (Masashi Kitamura) * @note * - Public Domain Software */ #ifndef PERFCNT_H #define PERFCNT_H #ifndef PERFCNT_T #ifdef _WIN32 #include <windows.h> typedef unsigned __int64 PERFCNT_T; inline PERFCNT_T PERFCNT_get() { PERFCNT_T c; QueryPerformanceCounter((LARGE_INTEGER*)&c); return c; } inline PERFCNT_T PERFCNT_per_sec() { static PERFCNT_T s = 0; if (!s) QueryPerformanceFrequency((LARGE_INTEGER*)&s); return s; } #elif defined LINUX #include <sys/resource.h> typedef unsigned long long PERFCNT_T; inline PERFCNT_T PERFCNT_get() { struct rusage t; getrusage(RUSAGE_SELF, &t); return t.ru_utime.tv_sec * 1000000ULL + t.ru_utime.tv_usec; } #define PERFCNT_per_sec() 1000000ULL #else #include <time.h> typedef clock_t PERFCNT_T; #define PERFCNT_get() clock() #define PERFCNT_per_sec() CLOCKS_PER_SEC #endif #define PERFCNT_TO_SEC(t) ((t) * 1.0 / PERFCNT_per_sec()) #define PERFCNT_TO_MILLI_SEC(t) ((t) * PERFCNT_T(1000) / PERFCNT_per_sec()) #define PERFCNT_TO_MICRO_SEC(t) ((t) * PERFCNT_T(1000000) / PERFCNT_per_sec()) #define PERFCNT_T PERFCNT_T #endif #endif