7#ifndef SECP256K1_BENCH_H
8#define SECP256K1_BENCH_H
15#if (defined(_MSC_VER) && _MSC_VER >= 1900)
22#if (defined(_MSC_VER) && _MSC_VER >= 1900)
25 if (!timespec_get(&tv, TIME_UTC)) {
26 fputs(
"timespec_get failed!", stderr);
29 return (int64_t)tv.tv_nsec / 1000 + (int64_t)tv.tv_sec * 1000000LL;
32 gettimeofday(&tv, NULL);
33 return (int64_t)tv.tv_usec + (int64_t)tv.tv_sec * 1000000LL;
38#define FP_MULT (1000000LL)
43 int c, i, rounding,
g;
52 x_abs = x < 0 ? -x : x;
66 for (i = c; i <
FP_EXP; ++i) {
67 rounding = (y % 10) >= 5;
73 ptr =
sizeof(buffer) - 1;
77 for (i = 0; i < c; ++i) {
78 buffer[--ptr] =
'0' + (y % 10);
86 buffer[--ptr] =
'0' + (y % 10);
94 printf(
"%5.*s",
g, &buffer[ptr]);
100 int64_t min = INT64_MAX;
103 for (i = 0; i <
count; i++) {
104 int64_t begin, total;
111 if (teardown != NULL) {
112 teardown(
data, iter);
132static int have_flag(
int argc,
char** argv,
char *flag) {
133 char** argm = argv + argc;
135 while (argv != argm) {
136 if (strcmp(*argv, flag) == 0) {
151 char** argm = argv + argc;
154 while (argv != argm) {
156 for (i = 0; i < n; i++) {
157 if (strcmp(*argv, valid_args[i]) == 0) {
162 if (found_valid == 0) {
171 char* env = getenv(
"SECP256K1_BENCH_ITERS");
173 return strtol(env, NULL, 0);
175 return default_iters;
180 char* bench_str =
"Benchmark";
181 char* min_str =
" Min(us) ";
182 char* avg_str =
" Avg(us) ";
183 char* max_str =
" Max(us) ";
184 printf(
"%-30s,%-15s,%-15s,%-15s\n", bench_str, min_str, avg_str, max_str);
static int get_iters(int default_iters)
static void print_output_table_header_row(void)
static void print_number(const int64_t x)
static int64_t gettime_i64(void)
static void run_benchmark(char *name, void(*benchmark)(void *, int), void(*setup)(void *), void(*teardown)(void *, int), void *data, int count, int iter)
static int have_invalid_args(int argc, char **argv, char **valid_args, size_t n)
static int have_flag(int argc, char **argv, char *flag)