summaryrefslogtreecommitdiffstats
path: root/benchmark/bench.h
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2024-12-02 19:05:25 -0500
committerDavid Robillard <d@drobilla.net>2024-12-02 19:16:37 -0500
commit41d771db17210d577b0a2227f95377186663600a (patch)
treee454be255deefd48d1e92919da7fe3f864c8c0f1 /benchmark/bench.h
parent2518f388bda4d1969d2153f909092aa443044d07 (diff)
downloadzix-41d771db17210d577b0a2227f95377186663600a.tar.gz
zix-41d771db17210d577b0a2227f95377186663600a.tar.bz2
zix-41d771db17210d577b0a2227f95377186663600a.zip
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.
Diffstat (limited to 'benchmark/bench.h')
-rw-r--r--benchmark/bench.h16
1 files 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 <d@drobilla.net>
+// Copyright 2011-2024 David Robillard <d@drobilla.net>
// SPDX-License-Identifier: ISC
#ifndef BENCH_H
#define BENCH_H
-#include <time.h>
+#include <glib.h>
-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);
}