Skip to content

Commit e2cfea0

Browse files
author
Sebastian Falbesoner
committed
bench: add --help option to bench_internal
1 parent e721039 commit e2cfea0

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/bench_internal.c

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,31 @@
1717
#include "ecmult_impl.h"
1818
#include "bench.h"
1919

20+
static void help(int default_iters) {
21+
printf("Benchmarks internal routines for the following areas:\n");
22+
printf(" - Scalar operations (modulo the curve's order)\n");
23+
printf(" - Field operations (modulo the curve's field size)\n");
24+
printf(" - Group operations (both in Jacobian and affine coordinates)\n");
25+
printf(" - Point multiplication\n");
26+
printf(" - Hash algorithms\n");
27+
printf(" - Context object handling\n");
28+
printf("\n");
29+
printf("The default number of iterations for each benchmark is %d. This can be\n", default_iters);
30+
printf("customized using the SECP256K1_BENCH_ITERS environment variable.\n");
31+
printf("\n");
32+
printf("Usage: ./bench_internal [args]\n");
33+
printf("By default, all benchmarks will be run.\n");
34+
printf("args:\n");
35+
printf(" help : display this help and exit\n");
36+
printf(" scalar : all scalar operations (add, half, inverse, mul, negate, split)\n");
37+
printf(" field : all field operations (half, inverse, issquare, mul, normalize, sqr, sqrt)\n");
38+
printf(" group : all group operations (add, double, to_affine)\n");
39+
printf(" ecmult : all point multiplication operations (ecmult_wnaf) \n");
40+
printf(" hash : all hash algorithms (hmac, rng6979, sha256)\n");
41+
printf(" context : all context object operations (context_create)\n");
42+
printf("\n");
43+
}
44+
2045
typedef struct {
2146
secp256k1_scalar scalar[2];
2247
secp256k1_fe fe[4];
@@ -365,8 +390,19 @@ static void bench_context(void* arg, int iters) {
365390

366391
int main(int argc, char **argv) {
367392
bench_inv data;
368-
int iters = get_iters(20000);
393+
int default_iters = 20000;
394+
int iters = get_iters(default_iters);
369395
int d = argc == 1; /* default */
396+
397+
if (argc > 1) {
398+
if (have_flag(argc, argv, "-h")
399+
|| have_flag(argc, argv, "--help")
400+
|| have_flag(argc, argv, "help")) {
401+
help(default_iters);
402+
return 0;
403+
}
404+
}
405+
370406
print_output_table_header_row();
371407

372408
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)