diff options
Diffstat (limited to 'yuvbench/kbench.h')
| -rw-r--r-- | yuvbench/kbench.h | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/yuvbench/kbench.h b/yuvbench/kbench.h index c5d4149..42ec646 100644 --- a/yuvbench/kbench.h +++ b/yuvbench/kbench.h @@ -9,6 +9,10 @@ double KBenchElapsedTime(uintptr_t t0, uintptr_t t1); #ifdef KBENCH_IMPLEMENTATION +#ifdef __linux__ +#include <time.h> +#endif + uintptr_t KBenchTS(void) { uintptr_t result = 0; @@ -16,6 +20,12 @@ uintptr_t KBenchTS(void) #if defined(__APPLE__) && defined(__clang__) && defined(__aarch64__) __asm__ volatile("mrs %0, CNTVCT_EL0" : "=r"(result) :: "memory"); #endif + // linux: use clock_gettime +#if defined(__linux__) + struct timespec ts; + clock_gettime(CLOCK_MONOTONIC, &ts); + result = (uintptr_t)ts.tv_sec * 1e9 + (uintptr_t)ts.tv_nsec; +#endif return result; } @@ -35,6 +45,10 @@ double KBenchElapsedTime(uintptr_t t0, uintptr_t t1) __asm__ volatile("mrs %0, CNTFRQ_EL0" : "=r"(cntfreq_el0) :: "memory"); val = (double)elapsed / (double)cntfreq_el0; #endif + // linux: use clock_gettime +#if defined(__linux__) && defined(__GNUC__) && defined(__amd64__) + val = (double)elapsed / 1e9; +#endif return val; } |