7#ifndef SECP256K1_BENCH_H
8#define SECP256K1_BENCH_H
15static int64_t gettime_i64(
void) {
17 gettimeofday(&tv, NULL);
22#define FP_MULT (1000000LL)
27 int c, i, rounding, g;
36 x_abs = x < 0 ? -x : x;
50 for (i = c; i <
FP_EXP; ++i) {
51 rounding = (y % 10) >= 5;
57 ptr =
sizeof(buffer) - 1;
61 for (i = 0; i < c; ++i) {
62 buffer[--ptr] =
'0' + (y % 10);
70 buffer[--ptr] =
'0' + (y % 10);
78 printf(
"%5.*s", g, &buffer[ptr]);
79 printf(
"%-*s",
FP_EXP, &buffer[ptr + g]);
82void run_benchmark(
char *
name,
void (*benchmark)(
void*,
int),
void (*setup)(
void*),
void (*teardown)(
void*,
int),
void* data,
int count,
int iter) {
87 for (i = 0; i <
count; i++) {
92 begin = gettime_i64();
93 benchmark(data, iter);
94 total = gettime_i64() - begin;
95 if (teardown != NULL) {
107 printf(
"%-30s, ",
name);
117 char** argm =
argv + argc;
119 while (
argv != argm) {
120 if (strcmp(*
argv, flag) == 0) {
135 char** argm =
argv + argc;
138 while (
argv != argm) {
140 for (i = 0; i < n; i++) {
141 if (strcmp(*
argv, valid_args[i]) == 0) {
146 if (found_valid == 0) {
155 char* env = getenv(
"SECP256K1_BENCH_ITERS");
157 return strtol(env, NULL, 0);
159 return default_iters;
164 char* bench_str =
"Benchmark";
165 char* min_str =
" Min(us) ";
166 char* avg_str =
" Avg(us) ";
167 char* max_str =
" Max(us) ";
168 printf(
"%-30s,%-15s,%-15s,%-15s\n", bench_str, min_str, avg_str, max_str);
void print_output_table_header_row(void)
int have_flag(int argc, char **argv, char *flag)
int get_iters(int default_iters)
void print_number(const int64_t x)
int have_invalid_args(int argc, char **argv, char **valid_args, size_t n)
void run_benchmark(char *name, void(*benchmark)(void *, int), void(*setup)(void *), void(*teardown)(void *, int), void *data, int count, int iter)