Skip to content

Commit 1ddd76a

Browse files
Sebastian FalbesonertheStack
Sebastian Falbesoner
authored andcommitted
bench: add --help option to bench_internal
1 parent e721039 commit 1ddd76a

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/bench_internal.c

+31-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,25 @@
1717
#include "ecmult_impl.h"
1818
#include "bench.h"
1919

20+
static void help(int default_iters) {
21+
printf("Benchmarks various internal routines.\n");
22+
printf("\n");
23+
printf("The default number of iterations for each benchmark is %d. This can be\n", default_iters);
24+
printf("customized using the SECP256K1_BENCH_ITERS environment variable.\n");
25+
printf("\n");
26+
printf("Usage: ./bench_internal [args]\n");
27+
printf("By default, all benchmarks will be run.\n");
28+
printf("args:\n");
29+
printf(" help : display this help and exit\n");
30+
printf(" scalar : all scalar operations (add, half, inverse, mul, negate, split)\n");
31+
printf(" field : all field operations (half, inverse, issquare, mul, normalize, sqr, sqrt)\n");
32+
printf(" group : all group operations (add, double, to_affine)\n");
33+
printf(" ecmult : all point multiplication operations (ecmult_wnaf) \n");
34+
printf(" hash : all hash algorithms (hmac, rng6979, sha256)\n");
35+
printf(" context : all context object operations (context_create)\n");
36+
printf("\n");
37+
}
38+
2039
typedef struct {
2140
secp256k1_scalar scalar[2];
2241
secp256k1_fe fe[4];
@@ -365,8 +384,19 @@ static void bench_context(void* arg, int iters) {
365384

366385
int main(int argc, char **argv) {
367386
bench_inv data;
368-
int iters = get_iters(20000);
387+
int default_iters = 20000;
388+
int iters = get_iters(default_iters);
369389
int d = argc == 1; /* default */
390+
391+
if (argc > 1) {
392+
if (have_flag(argc, argv, "-h")
393+
|| have_flag(argc, argv, "--help")
394+
|| have_flag(argc, argv, "help")) {
395+
help(default_iters);
396+
return 0;
397+
}
398+
}
399+
370400
print_output_table_header_row();
371401

372402
if (d || have_flag(argc, argv, "scalar") || have_flag(argc, argv, "half")) run_benchmark("scalar_half", bench_scalar_half, bench_setup, NULL, &data, 10, iters*100);

0 commit comments

Comments
 (0)