Add context building benchmarks

This commit is contained in:
Pieter Wuille 2015-08-20 21:26:22 +02:00
parent cc623d50e4
commit 2f77487012

View File

@ -16,6 +16,7 @@
#include "ecmult_const_impl.h" #include "ecmult_const_impl.h"
#include "ecmult_impl.h" #include "ecmult_impl.h"
#include "bench.h" #include "bench.h"
#include "secp256k1.c"
typedef struct { typedef struct {
secp256k1_scalar_t scalar_x, scalar_y; secp256k1_scalar_t scalar_x, scalar_y;
@ -282,6 +283,22 @@ void bench_rfc6979_hmac_sha256(void* arg) {
} }
} }
void bench_context_verify(void* arg) {
int i;
(void)arg;
for (i = 0; i < 20; i++) {
secp256k1_context_destroy(secp256k1_context_create(SECP256K1_CONTEXT_VERIFY));
}
}
void bench_context_sign(void* arg) {
int i;
(void)arg;
for (i = 0; i < 200; i++) {
secp256k1_context_destroy(secp256k1_context_create(SECP256K1_CONTEXT_SIGN));
}
}
int have_flag(int argc, char** argv, char *flag) { int have_flag(int argc, char** argv, char *flag) {
char** argm = argv + argc; char** argm = argv + argc;
@ -327,5 +344,9 @@ int main(int argc, char **argv) {
if (have_flag(argc, argv, "hash") || have_flag(argc, argv, "sha256")) run_benchmark("hash_sha256", bench_sha256, bench_setup, NULL, &data, 10, 20000); if (have_flag(argc, argv, "hash") || have_flag(argc, argv, "sha256")) run_benchmark("hash_sha256", bench_sha256, bench_setup, NULL, &data, 10, 20000);
if (have_flag(argc, argv, "hash") || have_flag(argc, argv, "hmac")) run_benchmark("hash_hmac_sha256", bench_hmac_sha256, bench_setup, NULL, &data, 10, 20000); if (have_flag(argc, argv, "hash") || have_flag(argc, argv, "hmac")) run_benchmark("hash_hmac_sha256", bench_hmac_sha256, bench_setup, NULL, &data, 10, 20000);
if (have_flag(argc, argv, "hash") || have_flag(argc, argv, "rng6979")) run_benchmark("hash_rfc6979_hmac_sha256", bench_rfc6979_hmac_sha256, bench_setup, NULL, &data, 10, 20000); if (have_flag(argc, argv, "hash") || have_flag(argc, argv, "rng6979")) run_benchmark("hash_rfc6979_hmac_sha256", bench_rfc6979_hmac_sha256, bench_setup, NULL, &data, 10, 20000);
if (have_flag(argc, argv, "context") || have_flag(argc, argv, "verify")) run_benchmark("context_verify", bench_context_verify, bench_setup, NULL, &data, 10, 20);
if (have_flag(argc, argv, "context") || have_flag(argc, argv, "sign")) run_benchmark("context_sign", bench_context_sign, bench_setup, NULL, &data, 10, 200);
return 0; return 0;
} }