From a05ce4cb27bfcf2236b621ffccf6448c64c42e07 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Thu, 31 Dec 2020 15:21:57 +0100 Subject: Fix includes in benchmark utilities --- benchmark/bench.h | 24 +++++++++++++++--------- 1 file 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 #include +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 -- cgit v1.2.1