#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "sys/time.h"
Go to the source code of this file.
|
void | print_number (const int64_t x) |
|
void | run_benchmark (char *name, void(*benchmark)(void *, int), void(*setup)(void *), void(*teardown)(void *, int), void *data, int count, int iter) |
|
int | have_flag (int argc, char **argv, char *flag) |
|
int | have_invalid_args (int argc, char **argv, char **valid_args, size_t n) |
|
int | get_iters (int default_iters) |
|
void | print_output_table_header_row (void) |
|
◆ FP_EXP
◆ FP_MULT
#define FP_MULT (1000000LL) |
◆ get_iters()
int get_iters |
( |
int | default_iters | ) |
|
Definition at line 154 of file bench.h.
154 {
155 char* env = getenv("SECP256K1_BENCH_ITERS");
156 if (env) {
157 return strtol(env, NULL, 0);
158 } else {
159 return default_iters;
160 }
161}
◆ have_flag()
int have_flag |
( |
int | argc, |
|
|
char ** | argv, |
|
|
char * | flag ) |
Definition at line 116 of file bench.h.
116 {
117 char** argm =
argv + argc;
119 while (
argv != argm) {
120 if (strcmp(*
argv, flag) == 0) {
121 return 1;
122 }
124 }
125 return 0;
126}
◆ have_invalid_args()
int have_invalid_args |
( |
int | argc, |
|
|
char ** | argv, |
|
|
char ** | valid_args, |
|
|
size_t | n ) |
Definition at line 132 of file bench.h.
132 {
133 size_t i;
134 int found_valid;
135 char** argm =
argv + argc;
137
138 while (
argv != argm) {
139 found_valid = 0;
140 for (i = 0; i < n; i++) {
141 if (strcmp(*
argv, valid_args[i]) == 0) {
142 found_valid = 1;
143 break;
144 }
145 }
146 if (found_valid == 0) {
147 return 1;
148 }
150 }
151 return 0;
152}
◆ print_number()
void print_number |
( |
const int64_t | x | ) |
|
Definition at line 25 of file bench.h.
25 {
27 int c, i, rounding, g;
28 size_t ptr;
29 char buffer[30];
30
32
34 return;
35 }
36 x_abs = x < 0 ? -x : x;
37
38
39
41 c = 0;
44 c++;
45 }
46
47
49 rounding = 0;
50 for (i = c; i <
FP_EXP; ++i) {
51 rounding = (
y % 10) >= 5;
53 }
55
56
57 ptr = sizeof(buffer) - 1;
58 buffer[ptr] = 0;
59 g = 0;
60 if (c != 0) {
61 for (i = 0; i < c; ++i) {
62 buffer[--ptr] =
'0' + (
y % 10);
64 }
65 } else if (c == 0) {
66 buffer[--ptr] = '0';
67 }
68 buffer[--ptr] = '.';
69 do {
70 buffer[--ptr] =
'0' + (
y % 10);
72 g++;
73 } while (y != 0);
74 if (x < 0) {
75 buffer[--ptr] = '-';
76 g++;
77 }
78 printf(
"%5.*s", g, &buffer[ptr]);
80}
LOGGING_API void printf(Category category, const char *format,...)
◆ print_output_table_header_row()
void print_output_table_header_row |
( |
void | | ) |
|
Definition at line 163 of file bench.h.
163 {
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);
170}
◆ run_benchmark()
void run_benchmark |
( |
char * | name, |
|
|
void(* | benchmark )(void *, int), |
|
|
void(* | setup )(void *), |
|
|
void(* | teardown )(void *, int), |
|
|
void * | data, |
|
|
int | count, |
|
|
int | iter ) |
Definition at line 82 of file bench.h.
82 {
83 int i;
87 for (i = 0; i <
count; i++) {
89 if (setup != NULL) {
90 setup(data);
91 }
92 begin = gettime_i64();
93 benchmark(data, iter);
94 total = gettime_i64() - begin;
95 if (teardown != NULL) {
96 teardown(data, iter);
97 }
98 if (total < min) {
100 }
101 if (total > max) {
102 max = total;
103 }
104 sum += total;
105 }
106
114}
void print_number(const int64_t x)
const T & min(const T &a, const T &b)