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 print_number(double x) {
26 while (y > 0 && y < 100.0) {
33 void run_benchmark(char *name, void (*benchmark)(void*), void (*setup)(void*), void (*teardown)(void*), void* data, int count, int iter) {
35 double min = HUGE_VAL;
38 for (i = 0; i < count; i++) {
43 begin = gettimedouble();
45 total = gettimedouble() - begin;
46 if (teardown != NULL) {
57 printf("%s: min ", name);
58 print_number(min * 1000000.0 / iter);
60 print_number((sum / count) * 1000000.0 / iter);
62 print_number(max * 1000000.0 / iter);
66 #endif /* SECP256K1_BENCH_H */