Changeset View
Changeset View
Standalone View
Standalone View
src/secp256k1/src/bench.h
Show First 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | do { | ||||
y /= 10; | y /= 10; | ||||
} while (y != 0); | } while (y != 0); | ||||
if (x < 0) { | if (x < 0) { | ||||
buffer[--ptr] = '-'; | buffer[--ptr] = '-'; | ||||
} | } | ||||
printf("%s", &buffer[ptr]); | printf("%s", &buffer[ptr]); | ||||
} | } | ||||
void run_benchmark(char *name, void (*benchmark)(void*), void (*setup)(void*), void (*teardown)(void*), void* data, int count, int iter) { | void run_benchmark(char *name, void (*benchmark)(void*, int), void (*setup)(void*), void (*teardown)(void*, int), void* data, int count, int iter) { | ||||
int i; | int i; | ||||
int64_t min = INT64_MAX; | int64_t min = INT64_MAX; | ||||
int64_t sum = 0; | int64_t sum = 0; | ||||
int64_t max = 0; | int64_t max = 0; | ||||
for (i = 0; i < count; i++) { | for (i = 0; i < count; i++) { | ||||
int64_t begin, total; | int64_t begin, total; | ||||
if (setup != NULL) { | if (setup != NULL) { | ||||
setup(data); | setup(data); | ||||
} | } | ||||
begin = gettime_i64(); | begin = gettime_i64(); | ||||
benchmark(data); | benchmark(data, iter); | ||||
total = gettime_i64() - begin; | total = gettime_i64() - begin; | ||||
if (teardown != NULL) { | if (teardown != NULL) { | ||||
teardown(data); | teardown(data, iter); | ||||
} | } | ||||
if (total < min) { | if (total < min) { | ||||
min = total; | min = total; | ||||
} | } | ||||
if (total > max) { | if (total > max) { | ||||
max = total; | max = total; | ||||
} | } | ||||
sum += total; | sum += total; | ||||
Show All 17 Lines | while (argv != NULL && argv != argm) { | ||||
if (strcmp(*argv, flag) == 0) { | if (strcmp(*argv, flag) == 0) { | ||||
return 1; | return 1; | ||||
} | } | ||||
argv++; | argv++; | ||||
} | } | ||||
return 0; | return 0; | ||||
} | } | ||||
int get_iters(int default_iters) { | |||||
char* env = getenv("SECP256K1_BENCH_ITERS"); | |||||
if (env) { | |||||
return strtol(env, NULL, 0); | |||||
} else { | |||||
return default_iters; | |||||
} | |||||
} | |||||
#endif /* SECP256K1_BENCH_H */ | #endif /* SECP256K1_BENCH_H */ |