diff options
author | David Robillard <d@drobilla.net> | 2020-12-31 15:21:57 +0100 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-12-31 15:21:57 +0100 |
commit | a05ce4cb27bfcf2236b621ffccf6448c64c42e07 (patch) | |
tree | 568be9e771e84479757911faf655452a9cce58f2 /benchmark | |
parent | b150a8cc7da022d3a894743060857648f8039716 (diff) | |
download | zix-a05ce4cb27bfcf2236b621ffccf6448c64c42e07.tar.gz zix-a05ce4cb27bfcf2236b621ffccf6448c64c42e07.tar.bz2 zix-a05ce4cb27bfcf2236b621ffccf6448c64c42e07.zip |
Fix includes in benchmark utilities
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/bench.h | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/benchmark/bench.h b/benchmark/bench.h index 3fc907f..6d181b2 100644 --- a/benchmark/bench.h +++ b/benchmark/bench.h @@ -14,30 +14,36 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifndef BENCH_H +#define BENCH_H + #define _POSIX_C_SOURCE 199309L -#include <sys/time.h> #include <time.h> +typedef struct timespec BenchmarkTime; + static inline double -elapsed_s(const struct timespec* start, const struct timespec* end) +bench_elapsed_s(const BenchmarkTime* start, const BenchmarkTime* end) { return ((double)(end->tv_sec - start->tv_sec) + ((double)(end->tv_nsec - start->tv_nsec) * 0.000000001)); } -static inline struct timespec +static inline BenchmarkTime bench_start(void) { - struct timespec start_t; - clock_gettime(CLOCK_MONOTONIC, &start_t); + BenchmarkTime start_t; + clock_gettime(CLOCK_REALTIME, &start_t); return start_t; } static inline double -bench_end(const struct timespec* start_t) +bench_end(const BenchmarkTime* start_t) { - struct timespec end_t; - clock_gettime(CLOCK_MONOTONIC, &end_t); - return elapsed_s(start_t, &end_t); + BenchmarkTime end_t; + clock_gettime(CLOCK_REALTIME, &end_t); + return bench_elapsed_s(start_t, &end_t); } + +#endif // BENCH_H |