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_
14 static double gettimedouble(void) {
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
;
24 for (int i
= 0; i
< count
; i
++) {
25 if (setup
) setup(data
);
26 double begin
= gettimedouble();
28 double total
= gettimedouble() - begin
;
29 if (teardown
) teardown(data
);
30 if (total
< min
) min
= total
;
31 if (total
> max
) max
= total
;
34 printf("min %.3fus / avg %.3fus / max %.3fus\n", min
* 1000000.0 / iter
, (sum
/ count
) * 1000000.0 / iter
, max
* 1000000.0 / iter
);