Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/bench.h
/********************************************************************** | /********************************************************************** | ||||
* Copyright (c) 2014 Pieter Wuille * | * Copyright (c) 2014 Pieter Wuille * | ||||
* Distributed under the MIT software license, see the accompanying * | * Distributed under the MIT software license, see the accompanying * | ||||
* file COPYING or http://www.opensource.org/licenses/mit-license.php.* | * file COPYING or http://www.opensource.org/licenses/mit-license.php.* | ||||
**********************************************************************/ | **********************************************************************/ | ||||
#ifndef SECP256K1_BENCH_H | #ifndef SECP256K1_BENCH_H | ||||
#define SECP256K1_BENCH_H | #define SECP256K1_BENCH_H | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <string.h> | |||||
#include <math.h> | #include <math.h> | ||||
#include "sys/time.h" | #include "sys/time.h" | ||||
static double gettimedouble(void) { | static double gettimedouble(void) { | ||||
struct timeval tv; | struct timeval tv; | ||||
gettimeofday(&tv, NULL); | gettimeofday(&tv, NULL); | ||||
return tv.tv_usec * 0.000001 + tv.tv_sec; | return tv.tv_usec * 0.000001 + tv.tv_sec; | ||||
} | } | ||||
Show All 39 Lines | void run_benchmark(char *name, void (*benchmark)(void*), void (*setup)(void*), void (*teardown)(void*), void* data, int count, int iter) { | ||||
print_number(min * 1000000.0 / iter); | print_number(min * 1000000.0 / iter); | ||||
printf("us / avg "); | printf("us / avg "); | ||||
print_number((sum / count) * 1000000.0 / iter); | print_number((sum / count) * 1000000.0 / iter); | ||||
printf("us / max "); | printf("us / max "); | ||||
print_number(max * 1000000.0 / iter); | print_number(max * 1000000.0 / iter); | ||||
printf("us\n"); | printf("us\n"); | ||||
} | } | ||||
int have_flag(int argc, char** argv, char *flag) { | |||||
char** argm = argv + argc; | |||||
argv++; | |||||
if (argv == argm) { | |||||
return 1; | |||||
} | |||||
while (argv != NULL && argv != argm) { | |||||
if (strcmp(*argv, flag) == 0) { | |||||
return 1; | |||||
} | |||||
argv++; | |||||
} | |||||
return 0; | |||||
} | |||||
#endif /* SECP256K1_BENCH_H */ | #endif /* SECP256K1_BENCH_H */ |