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-func.c | 35 +++++++---------------------------- 1 file changed, 7 insertions(+), 28 deletions(-) (limited to 'bench/benchmark-func.c') diff --git a/bench/benchmark-func.c b/bench/benchmark-func.c index 82368a7..fe7e160 100644 --- a/bench/benchmark-func.c +++ b/bench/benchmark-func.c @@ -1,16 +1,7 @@ +#include "benchmark.h" + #include -#include -#include -#include -#include -#include -#ifdef BENCHMARK_LIB -# include BENCHMARK_LIB -#else -# include "../zahl.h" -# define BIGINT_LIBRARY "libzahl" -#endif enum { HIGH_ONLY, @@ -34,24 +25,10 @@ struct function { size_t measurements; }; -#if defined(__x86_64__) -# undef clock_t -# define clock_t unsigned long long int -static inline clock_t rdtsc(void) -{ - unsigned int low, high; - __asm__ __volatile__ ("rdtsc" : "=a"(low), "=d"(high)); - return (clock_t)low | (((clock_t)high) << 32); -} -#else -# define rdtsc clock -#endif - #define M_MAX 200 static char buf[1000]; static z_t temp, temp2; -static clock_t start, end; static unsigned long long int measurements[M_MAX]; #if 1 @@ -124,12 +101,12 @@ gettime(size_t m) INSTRUCTION;\ INSTRUCTION;\ j = f->runs;\ - start = rdtsc();\ + TIC;\ while (j--) {\ INSTRUCTION;\ }\ - end = rdtsc();\ - measurements[k] = (unsigned long long int)(end - start);\ + TOC;\ + measurements[k] = TICKS;\ }\ printf("%llu\n", gettime(f->measurements));\ a++;\ @@ -301,6 +278,8 @@ main(int argc, char *argv[]) return 2; } + benchmark_init(); + if (setjmp(jmp)) { zperror(argv[0]); return 1; -- cgit v1.2.3-70-g09d2