From 95cec6a5ecfdc2a75ba041a6e9f9cd568d53a6fc Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 27 Apr 2016 21:39:19 +0200 Subject: More accurate benchmarking MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- bench/benchmark.c | 34 +++++++--------------------------- 1 file changed, 7 insertions(+), 27 deletions(-) (limited to 'bench/benchmark.c') diff --git a/bench/benchmark.c b/bench/benchmark.c index 87e15ca..485e2c4 100644 --- a/bench/benchmark.c +++ b/bench/benchmark.c @@ -1,49 +1,29 @@ -#include -#include - -#ifdef BENCHMARK_LIB -# include BENCHMARK_LIB -#else -# include "../zahl.h" -# define BIGINT_LIBRARY "libzahl" -#endif - - -#ifndef CLOCK_MONOTONIC_RAW -# define CLOCK_MONOTONIC_RAW CLOCK_MONOTONIC -#endif +#include "benchmark.h" #define BENCHMARK(INSTRUCTION, FAST)\ do {\ i = FAST ? 1000000L : 1000L;\ - clock_gettime(CLOCK_MONOTONIC_RAW, &start);\ + TIC;\ while (i--) {\ (void)INSTRUCTION;\ }\ - clock_gettime(CLOCK_MONOTONIC_RAW, &end);\ - end.tv_sec -= start.tv_sec;\ - end.tv_nsec -= start.tv_nsec;\ - if (end.tv_nsec < 0) {\ - end.tv_nsec += 1000000000L;\ - end.tv_sec -= 1;\ - }\ - printf("%s: %lli.%09li %s (152 bits)\n",\ - #INSTRUCTION,\ - (long long int)(end.tv_sec), end.tv_nsec,\ - FAST ? "µs" : "ms");\ + TOC;\ + printf("%s: %s %s (152 bits)\n",\ + #INSTRUCTION, STIME, FAST ? "µs" : "ms");\ } while (0) int main(int argc, char *argv[]) { - struct timespec start, end; char buf[1000]; z_t a, b, c, d, tiny; jmp_buf jmp; size_t i; + benchmark_init(); + if (setjmp(jmp)) { zperror(argv[0]); return 1; -- cgit v1.2.3-70-g09d2