diff options
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 |