Combine bench_sign and bench_verify into single bench
This commit is contained in:
parent
8fa41201bd
commit
2a7be678a6
|
@ -1,9 +1,7 @@
|
||||||
bench_inv
|
bench
|
||||||
bench_ecdh
|
bench_ecdh
|
||||||
bench_ecmult
|
bench_ecmult
|
||||||
bench_schnorrsig
|
bench_schnorrsig
|
||||||
bench_sign
|
|
||||||
bench_verify
|
|
||||||
bench_recover
|
bench_recover
|
||||||
bench_internal
|
bench_internal
|
||||||
tests
|
tests
|
||||||
|
|
|
@ -81,11 +81,9 @@ endif
|
||||||
|
|
||||||
noinst_PROGRAMS =
|
noinst_PROGRAMS =
|
||||||
if USE_BENCHMARK
|
if USE_BENCHMARK
|
||||||
noinst_PROGRAMS += bench_verify bench_sign bench_internal bench_ecmult
|
noinst_PROGRAMS += bench bench_internal bench_ecmult
|
||||||
bench_verify_SOURCES = src/bench_verify.c
|
bench_SOURCES = src/bench.c
|
||||||
bench_verify_LDADD = libsecp256k1.la $(SECP_LIBS) $(SECP_TEST_LIBS) $(COMMON_LIB)
|
bench_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)
|
|
||||||
bench_internal_SOURCES = src/bench_internal.c
|
bench_internal_SOURCES = src/bench_internal.c
|
||||||
bench_internal_LDADD = $(SECP_LIBS) $(COMMON_LIB)
|
bench_internal_LDADD = $(SECP_LIBS) $(COMMON_LIB)
|
||||||
bench_internal_CPPFLAGS = $(SECP_INCLUDES)
|
bench_internal_CPPFLAGS = $(SECP_INCLUDES)
|
||||||
|
|
|
@ -26,7 +26,7 @@ make
|
||||||
|
|
||||||
# Print information about binaries so that we can see that the architecture is correct
|
# Print information about binaries so that we can see that the architecture is correct
|
||||||
file *tests* || true
|
file *tests* || true
|
||||||
file bench_* || true
|
file bench* || true
|
||||||
file .libs/* || true
|
file .libs/* || true
|
||||||
|
|
||||||
# This tells `make check` to wrap test invocations.
|
# This tells `make check` to wrap test invocations.
|
||||||
|
@ -49,8 +49,7 @@ then
|
||||||
{
|
{
|
||||||
$EXEC ./bench_ecmult
|
$EXEC ./bench_ecmult
|
||||||
$EXEC ./bench_internal
|
$EXEC ./bench_internal
|
||||||
$EXEC ./bench_sign
|
$EXEC ./bench
|
||||||
$EXEC ./bench_verify
|
|
||||||
} >> bench.log 2>&1
|
} >> bench.log 2>&1
|
||||||
if [ "$RECOVERY" = "yes" ]
|
if [ "$RECOVERY" = "yes" ]
|
||||||
then
|
then
|
||||||
|
|
|
@ -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 main(void) {
|
||||||
int i;
|
int i;
|
||||||
secp256k1_pubkey pubkey;
|
secp256k1_pubkey pubkey;
|
||||||
|
@ -48,6 +84,7 @@ int main(void) {
|
||||||
|
|
||||||
int iters = get_iters(20000);
|
int iters = get_iters(20000);
|
||||||
|
|
||||||
|
/* ECDSA verification benchmark */
|
||||||
data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
|
data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
|
||||||
|
|
||||||
for (i = 0; i < 32; i++) {
|
for (i = 0; i < 32; i++) {
|
||||||
|
@ -67,5 +104,13 @@ int main(void) {
|
||||||
run_benchmark("ecdsa_verify", bench_verify, NULL, NULL, &data, 10, iters);
|
run_benchmark("ecdsa_verify", bench_verify, NULL, NULL, &data, 10, iters);
|
||||||
|
|
||||||
secp256k1_context_destroy(data.ctx);
|
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;
|
return 0;
|
||||||
}
|
}
|
|
@ -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;
|
|
||||||
}
|
|
Loading…
Reference in New Issue