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
15 static double gettimedouble(void) {
17 gettimeofday(&tv, NULL);
18 return tv.tv_usec * 0.000001 + tv.tv_sec;
21 void print_number(double x) {
27 while (y > 0 && y < 100.0) {
34 void run_benchmark(char *name, void (*benchmark)(void*), void (*setup)(void*), void (*teardown)(void*), void* data, int count, int iter) {
36 double min = HUGE_VAL;
39 for (i = 0; i < count; i++) {
44 begin = gettimedouble();
46 total = gettimedouble() - begin;
47 if (teardown != NULL) {
58 printf("%s: min ", name);
59 print_number(min * 1000000.0 / iter);
61 print_number((sum / count) * 1000000.0 / iter);
63 print_number(max * 1000000.0 / iter);
67 int have_flag(int argc, char** argv, char *flag) {
68 char** argm = argv + argc;
73 while (argv != NULL && argv != argm) {
74 if (strcmp(*argv, flag) == 0) {
82 #endif /* SECP256K1_BENCH_H */