From 41d771db17210d577b0a2227f95377186663600a Mon Sep 17 00:00:00 2001 From: David Robillard Date: Mon, 2 Dec 2024 19:05:25 -0500 Subject: Fix benchmark build on Windows Since these benchmarks depend on glib anyway (for comparison), portability hassles can be avoided here by just using glib for timing as well. --- benchmark/bench.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/benchmark/bench.h b/benchmark/bench.h index bcfe077..2a25b11 100644 --- a/benchmark/bench.h +++ b/benchmark/bench.h @@ -1,33 +1,29 @@ -// Copyright 2011-2020 David Robillard +// Copyright 2011-2024 David Robillard // SPDX-License-Identifier: ISC #ifndef BENCH_H #define BENCH_H -#include +#include -typedef struct timespec BenchmarkTime; +typedef gint64 BenchmarkTime; static inline double 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)); + return (double)(*end - *start) * 0.000001; } static inline BenchmarkTime bench_start(void) { - BenchmarkTime start_t; - clock_gettime(CLOCK_REALTIME, &start_t); - return start_t; + return g_get_monotonic_time(); } static inline double bench_end(const BenchmarkTime* start_t) { - BenchmarkTime end_t; - clock_gettime(CLOCK_REALTIME, &end_t); + const BenchmarkTime end_t = g_get_monotonic_time(); return bench_elapsed_s(start_t, &end_t); } -- cgit v1.2.1