From 2a7be678a660d58742b1e767444c0fe75fa22592 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sun, 17 Oct 2021 12:08:06 -0400 Subject: [PATCH 1/5] Combine bench_sign and bench_verify into single bench --- .gitignore | 4 +-- Makefile.am | 8 ++--- ci/cirrus.sh | 5 ++- src/{bench_verify.c => bench.c} | 45 +++++++++++++++++++++++++ src/bench_sign.c | 60 --------------------------------- 5 files changed, 51 insertions(+), 71 deletions(-) rename src/{bench_verify.c => bench.c} (67%) delete mode 100644 src/bench_sign.c diff --git a/.gitignore b/.gitignore index aa7009af14855..2ed952579443a 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,7 @@ -bench_inv +bench bench_ecdh bench_ecmult bench_schnorrsig -bench_sign -bench_verify bench_recover bench_internal tests diff --git a/Makefile.am b/Makefile.am index a04ad05e8dccf..aa8014f5b6663 100644 --- a/Makefile.am +++ b/Makefile.am @@ -81,11 +81,9 @@ endif noinst_PROGRAMS = if USE_BENCHMARK -noinst_PROGRAMS += bench_verify bench_sign bench_internal bench_ecmult -bench_verify_SOURCES = src/bench_verify.c -bench_verify_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB) -bench_sign_SOURCES = src/bench_sign.c -bench_sign_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB) +noinst_PROGRAMS += bench bench_internal bench_ecmult +bench_SOURCES = src/bench.c +bench_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB) bench_internal_SOURCES = src/bench_internal.c bench_internal_LDADD = $(SECP_LIBS) $(COMMON_LIB) bench_internal_CPPFLAGS = $(SECP_INCLUDES) diff --git a/ci/cirrus.sh b/ci/cirrus.sh index 27db1e6779fa6..a87494314cbcc 100755 --- a/ci/cirrus.sh +++ b/ci/cirrus.sh @@ -26,7 +26,7 @@ make # Print information about binaries so that we can see that the architecture is correct file *tests* || true -file bench_* || true +file bench* || true file .libs/* || true # This tells `make check` to wrap test invocations. @@ -49,8 +49,7 @@ then { $EXEC ./bench_ecmult $EXEC ./bench_internal - $EXEC ./bench_sign - $EXEC ./bench_verify + $EXEC ./bench } >> bench.log 2>&1 if [ "$RECOVERY" = "yes" ] then diff --git a/src/bench_verify.c b/src/bench.c similarity index 67% rename from src/bench_verify.c rename to src/bench.c index d62e34b77ec16..704c7c09ca412 100644 --- a/src/bench_verify.c +++ b/src/bench.c @@ -40,6 +40,42 @@ static void bench_verify(void* arg, int iters) { } } +typedef struct { + secp256k1_context* ctx; + unsigned char msg[32]; + unsigned char key[32]; +} bench_sign_data; + +static void bench_sign_setup(void* arg) { + int i; + bench_sign_data *data = (bench_sign_data*)arg; + + for (i = 0; i < 32; i++) { + data->msg[i] = i + 1; + } + for (i = 0; i < 32; i++) { + data->key[i] = i + 65; + } +} + +static void bench_sign_run(void* arg, int iters) { + int i; + bench_sign_data *data = (bench_sign_data*)arg; + + unsigned char sig[74]; + for (i = 0; i < iters; i++) { + size_t siglen = 74; + int j; + secp256k1_ecdsa_signature signature; + CHECK(secp256k1_ecdsa_sign(data->ctx, &signature, data->msg, data->key, NULL, NULL)); + CHECK(secp256k1_ecdsa_signature_serialize_der(data->ctx, sig, &siglen, &signature)); + for (j = 0; j < 32; j++) { + data->msg[j] = sig[j]; + data->key[j] = sig[j + 32]; + } + } +} + int main(void) { int i; secp256k1_pubkey pubkey; @@ -48,6 +84,7 @@ int main(void) { int iters = get_iters(20000); + /* ECDSA verification benchmark */ data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY); for (i = 0; i < 32; i++) { @@ -67,5 +104,13 @@ int main(void) { 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); + + secp256k1_context_destroy(data.ctx); + return 0; } diff --git a/src/bench_sign.c b/src/bench_sign.c deleted file mode 100644 index c44f7b10ba846..0000000000000 --- a/src/bench_sign.c +++ /dev/null @@ -1,60 +0,0 @@ -/*********************************************************************** - * Copyright (c) 2014 Pieter Wuille * - * Distributed under the MIT software license, see the accompanying * - * file COPYING or https://www.opensource.org/licenses/mit-license.php.* - ***********************************************************************/ - -#include "../include/secp256k1.h" -#include "util.h" -#include "bench.h" - -typedef struct { - secp256k1_context* ctx; - unsigned char msg[32]; - unsigned char key[32]; -} bench_sign_data; - -static void bench_sign_setup(void* arg) { - int i; - bench_sign_data *data = (bench_sign_data*)arg; - - for (i = 0; i < 32; i++) { - data->msg[i] = i + 1; - } - for (i = 0; i < 32; i++) { - data->key[i] = i + 65; - } -} - -static void bench_sign_run(void* arg, int iters) { - int i; - bench_sign_data *data = (bench_sign_data*)arg; - - unsigned char sig[74]; - for (i = 0; i < iters; i++) { - size_t siglen = 74; - int j; - secp256k1_ecdsa_signature signature; - CHECK(secp256k1_ecdsa_sign(data->ctx, &signature, data->msg, data->key, NULL, NULL)); - CHECK(secp256k1_ecdsa_signature_serialize_der(data->ctx, sig, &siglen, &signature)); - for (j = 0; j < 32; j++) { - data->msg[j] = sig[j]; - data->key[j] = sig[j + 32]; - } - } -} - -int main(void) { - bench_sign_data data; - - int iters = get_iters(20000); - - data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN); - - print_output_table_header_row(); - - run_benchmark("ecdsa_sign", bench_sign_run, bench_sign_setup, NULL, &data, 10, iters); - - secp256k1_context_destroy(data.ctx); - return 0; -} From 855e18d8a809b98a622ab55765792aca132ea640 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sun, 17 Oct 2021 12:10:23 -0400 Subject: [PATCH 2/5] Merge bench_ecdh into bench --- .gitignore | 1 - ci/cirrus.sh | 4 ---- src/bench.c | 9 +++++++++ src/modules/ecdh/Makefile.am.include | 6 +----- src/{bench_ecdh.c => modules/ecdh/bench_impl.h} | 15 +++++---------- 5 files changed, 15 insertions(+), 20 deletions(-) rename src/{bench_ecdh.c => modules/ecdh/bench_impl.h} (89%) diff --git a/.gitignore b/.gitignore index 2ed952579443a..4c3aaa32d4b31 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,4 @@ bench -bench_ecdh bench_ecmult bench_schnorrsig bench_recover diff --git a/ci/cirrus.sh b/ci/cirrus.sh index a87494314cbcc..e48c899bc1234 100755 --- a/ci/cirrus.sh +++ b/ci/cirrus.sh @@ -55,10 +55,6 @@ then then $EXEC ./bench_recover >> bench.log 2>&1 fi - if [ "$ECDH" = "yes" ] - then - $EXEC ./bench_ecdh >> bench.log 2>&1 - fi if [ "$SCHNORRSIG" = "yes" ] then $EXEC ./bench_schnorrsig >> bench.log 2>&1 diff --git a/src/bench.c b/src/bench.c index 704c7c09ca412..de74dd25e1b8d 100644 --- a/src/bench.c +++ b/src/bench.c @@ -76,6 +76,10 @@ static void bench_sign_run(void* arg, int iters) { } } +#ifdef ENABLE_MODULE_ECDH +# include "modules/ecdh/bench_impl.h" +#endif + int main(void) { int i; secp256k1_pubkey pubkey; @@ -112,5 +116,10 @@ int main(void) { secp256k1_context_destroy(data.ctx); +#ifdef ENABLE_MODULE_ECDH + /* ECDH benchmarks */ + run_ecdh_bench(iters); +#endif + return 0; } diff --git a/src/modules/ecdh/Makefile.am.include b/src/modules/ecdh/Makefile.am.include index e3088b469790b..7f7f95f1fd6a5 100644 --- a/src/modules/ecdh/Makefile.am.include +++ b/src/modules/ecdh/Makefile.am.include @@ -1,8 +1,4 @@ include_HEADERS += include/secp256k1_ecdh.h noinst_HEADERS += src/modules/ecdh/main_impl.h noinst_HEADERS += src/modules/ecdh/tests_impl.h -if USE_BENCHMARK -noinst_PROGRAMS += bench_ecdh -bench_ecdh_SOURCES = src/bench_ecdh.c -bench_ecdh_LDADD = libsecp256k1.la $(SECP_LIBS) $(COMMON_LIB) -endif +noinst_HEADERS += src/modules/ecdh/bench_impl.h diff --git a/src/bench_ecdh.c b/src/modules/ecdh/bench_impl.h similarity index 89% rename from src/bench_ecdh.c rename to src/modules/ecdh/bench_impl.h index b6d4ee2941910..0b8b74e2306ae 100644 --- a/src/bench_ecdh.c +++ b/src/modules/ecdh/bench_impl.h @@ -4,12 +4,10 @@ * file COPYING or https://www.opensource.org/licenses/mit-license.php.* ***********************************************************************/ -#include +#ifndef SECP256K1_MODULE_ECDH_BENCH_H +#define SECP256K1_MODULE_ECDH_BENCH_H -#include "../include/secp256k1.h" #include "../include/secp256k1_ecdh.h" -#include "util.h" -#include "bench.h" typedef struct { secp256k1_context *ctx; @@ -44,18 +42,15 @@ static void bench_ecdh(void* arg, int iters) { } } -int main(void) { +void run_ecdh_bench(int iters) { bench_ecdh_data data; - int iters = get_iters(20000); - /* create a context with no capabilities */ data.ctx = secp256k1_context_create(SECP256K1_FLAGS_TYPE_CONTEXT); - print_output_table_header_row(); - run_benchmark("ecdh", bench_ecdh, bench_ecdh_setup, NULL, &data, 10, iters); secp256k1_context_destroy(data.ctx); - return 0; } + +#endif /* SECP256K1_MODULE_ECDH_BENCH_H */ From 3208557ae1062f7fcce25d5f2c5a29dc34a18895 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sun, 17 Oct 2021 13:56:59 -0400 Subject: [PATCH 3/5] Merge bench_recover into bench --- .gitignore | 1 - ci/cirrus.sh | 4 ---- src/bench.c | 9 +++++++++ src/modules/recovery/Makefile.am.include | 6 +----- .../recovery/bench_impl.h} | 15 ++++++--------- 5 files changed, 16 insertions(+), 19 deletions(-) rename src/{bench_recover.c => modules/recovery/bench_impl.h} (91%) diff --git a/.gitignore b/.gitignore index 4c3aaa32d4b31..599a2ef59f4bb 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ bench bench_ecmult bench_schnorrsig -bench_recover bench_internal tests exhaustive_tests diff --git a/ci/cirrus.sh b/ci/cirrus.sh index e48c899bc1234..86d2f06b139bc 100755 --- a/ci/cirrus.sh +++ b/ci/cirrus.sh @@ -51,10 +51,6 @@ then $EXEC ./bench_internal $EXEC ./bench } >> bench.log 2>&1 - if [ "$RECOVERY" = "yes" ] - then - $EXEC ./bench_recover >> bench.log 2>&1 - fi if [ "$SCHNORRSIG" = "yes" ] then $EXEC ./bench_schnorrsig >> bench.log 2>&1 diff --git a/src/bench.c b/src/bench.c index de74dd25e1b8d..6b457b88f4e07 100644 --- a/src/bench.c +++ b/src/bench.c @@ -80,6 +80,10 @@ static void bench_sign_run(void* arg, int iters) { # include "modules/ecdh/bench_impl.h" #endif +#ifdef ENABLE_MODULE_RECOVERY +# include "modules/recovery/bench_impl.h" +#endif + int main(void) { int i; secp256k1_pubkey pubkey; @@ -121,5 +125,10 @@ int main(void) { run_ecdh_bench(iters); #endif +#ifdef ENABLE_MODULE_RECOVERY + /* ECDSA recovery benchmarks */ + run_recovery_bench(iters); +#endif + return 0; } diff --git a/src/modules/recovery/Makefile.am.include b/src/modules/recovery/Makefile.am.include index e2d3f1248d25c..156ea690fad01 100644 --- a/src/modules/recovery/Makefile.am.include +++ b/src/modules/recovery/Makefile.am.include @@ -2,8 +2,4 @@ include_HEADERS += include/secp256k1_recovery.h noinst_HEADERS += src/modules/recovery/main_impl.h noinst_HEADERS += src/modules/recovery/tests_impl.h noinst_HEADERS += src/modules/recovery/tests_exhaustive_impl.h -if USE_BENCHMARK -noinst_PROGRAMS += bench_recover -bench_recover_SOURCES = src/bench_recover.c -bench_recover_LDADD = libsecp256k1.la $(SECP_LIBS) $(COMMON_LIB) -endif +noinst_HEADERS += src/modules/recovery/bench_impl.h diff --git a/src/bench_recover.c b/src/modules/recovery/bench_impl.h similarity index 91% rename from src/bench_recover.c rename to src/modules/recovery/bench_impl.h index 3ccd86dd9bacd..95330b1e5472d 100644 --- a/src/bench_recover.c +++ b/src/modules/recovery/bench_impl.h @@ -4,10 +4,10 @@ * file COPYING or https://www.opensource.org/licenses/mit-license.php.* ***********************************************************************/ -#include "../include/secp256k1.h" +#ifndef SECP256K1_MODULE_RECOVERY_BENCH_H +#define SECP256K1_MODULE_RECOVERY_BENCH_H + #include "../include/secp256k1_recovery.h" -#include "util.h" -#include "bench.h" typedef struct { secp256k1_context *ctx; @@ -48,17 +48,14 @@ void bench_recover_setup(void* arg) { } } -int main(void) { +void run_recovery_bench(int iters) { bench_recover_data data; - int iters = get_iters(20000); - data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY); - print_output_table_header_row(); - run_benchmark("ecdsa_recover", bench_recover, bench_recover_setup, NULL, &data, 10, iters); secp256k1_context_destroy(data.ctx); - return 0; } + +#endif /* SECP256K1_MODULE_RECOVERY_BENCH_H */ From 9f56bdf5b9ba2e22e77c6adaaeb8302398732df3 Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Sun, 17 Oct 2021 14:02:10 -0400 Subject: [PATCH 4/5] Merge bench_schnorrsig into bench --- .gitignore | 1 - ci/cirrus.sh | 4 ---- src/bench.c | 9 +++++++++ src/modules/schnorrsig/Makefile.am.include | 6 +----- .../schnorrsig/bench_impl.h} | 17 ++++++----------- 5 files changed, 16 insertions(+), 21 deletions(-) rename src/{bench_schnorrsig.c => modules/schnorrsig/bench_impl.h} (92%) diff --git a/.gitignore b/.gitignore index 599a2ef59f4bb..f3ed1c488f1cf 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,5 @@ bench bench_ecmult -bench_schnorrsig bench_internal tests exhaustive_tests diff --git a/ci/cirrus.sh b/ci/cirrus.sh index 86d2f06b139bc..39ec2adbee07b 100755 --- a/ci/cirrus.sh +++ b/ci/cirrus.sh @@ -51,10 +51,6 @@ then $EXEC ./bench_internal $EXEC ./bench } >> bench.log 2>&1 - if [ "$SCHNORRSIG" = "yes" ] - then - $EXEC ./bench_schnorrsig >> bench.log 2>&1 - fi fi if [ "$CTIMETEST" = "yes" ] then diff --git a/src/bench.c b/src/bench.c index 6b457b88f4e07..f46d5d60fcb79 100644 --- a/src/bench.c +++ b/src/bench.c @@ -84,6 +84,10 @@ static void bench_sign_run(void* arg, int iters) { # include "modules/recovery/bench_impl.h" #endif +#ifdef ENABLE_MODULE_SCHNORRSIG +# include "modules/schnorrsig/bench_impl.h" +#endif + int main(void) { int i; secp256k1_pubkey pubkey; @@ -130,5 +134,10 @@ int main(void) { run_recovery_bench(iters); #endif +#ifdef ENABLE_MODULE_SCHNORRSIG + /* Schnorr signature benchmarks */ + run_schnorrsig_bench(iters); +#endif + return 0; } diff --git a/src/modules/schnorrsig/Makefile.am.include b/src/modules/schnorrsig/Makefile.am.include index 568bcc35232d5..654fa2e5ae5a4 100644 --- a/src/modules/schnorrsig/Makefile.am.include +++ b/src/modules/schnorrsig/Makefile.am.include @@ -2,8 +2,4 @@ include_HEADERS += include/secp256k1_schnorrsig.h noinst_HEADERS += src/modules/schnorrsig/main_impl.h noinst_HEADERS += src/modules/schnorrsig/tests_impl.h noinst_HEADERS += src/modules/schnorrsig/tests_exhaustive_impl.h -if USE_BENCHMARK -noinst_PROGRAMS += bench_schnorrsig -bench_schnorrsig_SOURCES = src/bench_schnorrsig.c -bench_schnorrsig_LDADD = libsecp256k1.la $(SECP_LIBS) $(COMMON_LIB) -endif +noinst_HEADERS += src/modules/schnorrsig/bench_impl.h diff --git a/src/bench_schnorrsig.c b/src/modules/schnorrsig/bench_impl.h similarity index 92% rename from src/bench_schnorrsig.c rename to src/modules/schnorrsig/bench_impl.h index e30735d8b9ee2..2f2c8db073a56 100644 --- a/src/bench_schnorrsig.c +++ b/src/modules/schnorrsig/bench_impl.h @@ -4,14 +4,10 @@ * file COPYING or https://www.opensource.org/licenses/mit-license.php.* ***********************************************************************/ -#include -#include +#ifndef SECP256K1_MODULE_SCHNORRSIG_BENCH_H +#define SECP256K1_MODULE_SCHNORRSIG_BENCH_H - -#include "../include/secp256k1.h" -#include "../include/secp256k1_schnorrsig.h" -#include "util.h" -#include "bench.h" +#include "../../../include/secp256k1_schnorrsig.h" #define MSGLEN 32 @@ -49,10 +45,9 @@ void bench_schnorrsig_verify(void* arg, int iters) { } } -int main(void) { +void run_schnorrsig_bench(int iters) { int i; bench_schnorrsig_data data; - int iters = get_iters(10000); data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY | SECP256K1_CONTEXT_SIGN); data.keypairs = (const secp256k1_keypair **)malloc(iters * sizeof(secp256k1_keypair *)); @@ -86,7 +81,6 @@ int main(void) { CHECK(secp256k1_xonly_pubkey_serialize(data.ctx, pk_char, &pk) == 1); } - print_output_table_header_row(); 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); @@ -102,5 +96,6 @@ int main(void) { free(data.sigs); secp256k1_context_destroy(data.ctx); - return 0; } + +#endif From af6abcb3d0097a7f7892fb8b54a4c6363e5c2c7f Mon Sep 17 00:00:00 2001 From: Pieter Wuille Date: Fri, 5 Nov 2021 17:48:18 -0400 Subject: [PATCH 5/5] Make bench support selecting which benchmarks to run --- src/bench.c | 13 +++++++------ src/modules/ecdh/bench_impl.h | 5 +++-- src/modules/recovery/bench_impl.h | 5 +++-- src/modules/schnorrsig/bench_impl.h | 7 ++++--- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/bench.c b/src/bench.c index f46d5d60fcb79..dfc0470be608e 100644 --- a/src/bench.c +++ b/src/bench.c @@ -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 */ @@ -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; diff --git a/src/modules/ecdh/bench_impl.h b/src/modules/ecdh/bench_impl.h index 0b8b74e2306ae..94d833462fe0f 100644 --- a/src/modules/ecdh/bench_impl.h +++ b/src/modules/ecdh/bench_impl.h @@ -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); } diff --git a/src/modules/recovery/bench_impl.h b/src/modules/recovery/bench_impl.h index 95330b1e5472d..4a9e886910b8e 100644 --- a/src/modules/recovery/bench_impl.h +++ b/src/modules/recovery/bench_impl.h @@ -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); } diff --git a/src/modules/schnorrsig/bench_impl.h b/src/modules/schnorrsig/bench_impl.h index 2f2c8db073a56..41f393c84d7f0 100644 --- a/src/modules/schnorrsig/bench_impl.h +++ b/src/modules/schnorrsig/bench_impl.h @@ -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 *)); @@ -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]);