Update libsecp256k1
[bitcoinplatinum.git] / src / secp256k1 / src / bench.h
blob668ec39f71571e09ed60558e28861205c3f5a5bc
1 /**********************************************************************
2 * Copyright (c) 2014 Pieter Wuille *
3 * Distributed under the MIT software license, see the accompanying *
4 * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
5 **********************************************************************/
7 #ifndef _SECP256K1_BENCH_H_
8 #define _SECP256K1_BENCH_H_
10 #include <stdio.h>
11 #include <math.h>
12 #include "sys/time.h"
14 static double gettimedouble(void) {
15 struct timeval tv;
16 gettimeofday(&tv, NULL);
17 return tv.tv_usec * 0.000001 + tv.tv_sec;
20 void run_benchmark(void (*benchmark)(void*), void (*setup)(void*), void (*teardown)(void*), void* data, int count, int iter) {
21 double min = HUGE_VAL;
22 double sum = 0.0;
23 double max = 0.0;
24 for (int i = 0; i < count; i++) {
25 if (setup) setup(data);
26 double begin = gettimedouble();
27 benchmark(data);
28 double total = gettimedouble() - begin;
29 if (teardown) teardown(data);
30 if (total < min) min = total;
31 if (total > max) max = total;
32 sum += total;
34 printf("min %.3fus / avg %.3fus / max %.3fus\n", min * 1000000.0 / iter, (sum / count) * 1000000.0 / iter, max * 1000000.0 / iter);
37 #endif