diff options
| author | Mattias Andrée <maandree@kth.se> | 2016-04-27 21:39:19 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2016-04-27 21:39:19 +0200 |
| commit | 95cec6a5ecfdc2a75ba041a6e9f9cd568d53a6fc (patch) | |
| tree | b3cf3c526987b7970faf72fdaaf91cb753b28353 /bench/benchmark-func.c | |
| parent | Document UNSAFE (diff) | |
| download | libzahl-95cec6a5ecfdc2a75ba041a6e9f9cd568d53a6fc.tar.gz libzahl-95cec6a5ecfdc2a75ba041a6e9f9cd568d53a6fc.tar.bz2 libzahl-95cec6a5ecfdc2a75ba041a6e9f9cd568d53a6fc.tar.xz | |
More accurate benchmarking
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'bench/benchmark-func.c')
| -rw-r--r-- | bench/benchmark-func.c | 35 |
1 files changed, 7 insertions, 28 deletions
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 <limits.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <time.h> -#include <unistd.h> -#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; |
