Skip to content

Commit

Permalink
Make bench support selecting which benchmarks to run
Browse files Browse the repository at this point in the history
  • Loading branch information
sipa committed Nov 5, 2021
1 parent 9f56bdf commit af6abcb
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
13 changes: 7 additions & 6 deletions src/bench.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ static void bench_sign_run(void* arg, int iters) {
# include "modules/schnorrsig/bench_impl.h"
#endif

int main(void) {
int main(int argc, char** argv) {
int i;
secp256k1_pubkey pubkey;
secp256k1_ecdsa_signature sig;
bench_verify_data data;

int d = argc == 1;
int iters = get_iters(20000);

/* ECDSA verification benchmark */
Expand All @@ -113,30 +114,30 @@ int main(void) {
CHECK(secp256k1_ec_pubkey_serialize(data.ctx, data.pubkey, &data.pubkeylen, &pubkey, SECP256K1_EC_COMPRESSED) == 1);

print_output_table_header_row();
run_benchmark("ecdsa_verify", bench_verify, NULL, NULL, &data, 10, iters);
if (d || have_flag(argc, argv, "ecdsa") || have_flag(argc, argv, "verify") || have_flag(argc, argv, "ecdsa_verify")) run_benchmark("ecdsa_verify", bench_verify, NULL, NULL, &data, 10, iters);

secp256k1_context_destroy(data.ctx);

/* ECDSA signing benchmark */
data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN);

run_benchmark("ecdsa_sign", bench_sign_run, bench_sign_setup, NULL, &data, 10, iters);
if (d || have_flag(argc, argv, "ecdsa") || have_flag(argc, argv, "sign") || have_flag(argc, argv, "ecdsa_sign")) run_benchmark("ecdsa_sign", bench_sign_run, bench_sign_setup, NULL, &data, 10, iters);

secp256k1_context_destroy(data.ctx);

#ifdef ENABLE_MODULE_ECDH
/* ECDH benchmarks */
run_ecdh_bench(iters);
run_ecdh_bench(iters, argc, argv);
#endif

#ifdef ENABLE_MODULE_RECOVERY
/* ECDSA recovery benchmarks */
run_recovery_bench(iters);
run_recovery_bench(iters, argc, argv);
#endif

#ifdef ENABLE_MODULE_SCHNORRSIG
/* Schnorr signature benchmarks */
run_schnorrsig_bench(iters);
run_schnorrsig_bench(iters, argc, argv);
#endif

return 0;
Expand Down
5 changes: 3 additions & 2 deletions src/modules/ecdh/bench_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,14 @@ static void bench_ecdh(void* arg, int iters) {
}
}

void run_ecdh_bench(int iters) {
void run_ecdh_bench(int iters, int argc, char** argv) {
bench_ecdh_data data;
int d = argc == 1;

/* create a context with no capabilities */
data.ctx = secp256k1_context_create(SECP256K1_FLAGS_TYPE_CONTEXT);

run_benchmark("ecdh", bench_ecdh, bench_ecdh_setup, NULL, &data, 10, iters);
if (d || have_flag(argc, argv, "ecdh")) run_benchmark("ecdh", bench_ecdh, bench_ecdh_setup, NULL, &data, 10, iters);

secp256k1_context_destroy(data.ctx);
}
Expand Down
5 changes: 3 additions & 2 deletions src/modules/recovery/bench_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,13 @@ void bench_recover_setup(void* arg) {
}
}

void run_recovery_bench(int iters) {
void run_recovery_bench(int iters, int argc, char** argv) {
bench_recover_data data;
int d = argc == 1;

data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY);

run_benchmark("ecdsa_recover", bench_recover, bench_recover_setup, NULL, &data, 10, iters);
if (d || have_flag(argc, argv, "ecdsa") || have_flag(argc, argv, "recover") || have_flag(argc, argv, "ecdsa_recover")) run_benchmark("ecdsa_recover", bench_recover, bench_recover_setup, NULL, &data, 10, iters);

secp256k1_context_destroy(data.ctx);
}
Expand Down
7 changes: 4 additions & 3 deletions src/modules/schnorrsig/bench_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,10 @@ void bench_schnorrsig_verify(void* arg, int iters) {
}
}

void run_schnorrsig_bench(int iters) {
void run_schnorrsig_bench(int iters, int argc, char** argv) {
int i;
bench_schnorrsig_data data;
int d = argc == 1;

data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY | SECP256K1_CONTEXT_SIGN);
data.keypairs = (const secp256k1_keypair **)malloc(iters * sizeof(secp256k1_keypair *));
Expand Down Expand Up @@ -81,8 +82,8 @@ void run_schnorrsig_bench(int iters) {
CHECK(secp256k1_xonly_pubkey_serialize(data.ctx, pk_char, &pk) == 1);
}

run_benchmark("schnorrsig_sign", bench_schnorrsig_sign, NULL, NULL, (void *) &data, 10, iters);
run_benchmark("schnorrsig_verify", bench_schnorrsig_verify, NULL, NULL, (void *) &data, 10, iters);
if (d || have_flag(argc, argv, "schnorrsig") || have_flag(argc, argv, "sign") || have_flag(argc, argv, "schnorrsig_sign")) run_benchmark("schnorrsig_sign", bench_schnorrsig_sign, NULL, NULL, (void *) &data, 10, iters);
if (d || have_flag(argc, argv, "schnorrsig") || have_flag(argc, argv, "verify") || have_flag(argc, argv, "schnorrsig_verify")) run_benchmark("schnorrsig_verify", bench_schnorrsig_verify, NULL, NULL, (void *) &data, 10, iters);

for (i = 0; i < iters; i++) {
free((void *)data.keypairs[i]);
Expand Down

0 comments on commit af6abcb

Please sign in to comment.