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.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.c')
| -rw-r--r-- | bench/benchmark.c | 34 |
1 files changed, 7 insertions, 27 deletions
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 <time.h> -#include <stdio.h> - -#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; |
