Skip to content

Commit

Permalink
Add flags for choosing algorithm in ecmult_multi benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasnick committed Dec 7, 2017
1 parent 36b22c9 commit a58f543
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 17 deletions.
16 changes: 16 additions & 0 deletions src/bench.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#define SECP256K1_BENCH_H

#include <stdio.h>
#include <string.h>
#include <math.h>
#include "sys/time.h"

Expand Down Expand Up @@ -63,4 +64,19 @@ void run_benchmark(char *name, void (*benchmark)(void*), void (*setup)(void*), v
printf("us\n");
}

int have_flag(int argc, char** argv, char *flag) {
char** argm = argv + argc;
argv++;
if (argv == argm) {
return 1;
}
while (argv != NULL && argv != argm) {
if (strcmp(*argv, flag) == 0) {
return 1;
}
argv++;
}
return 0;
}

#endif /* SECP256K1_BENCH_H */
19 changes: 17 additions & 2 deletions src/bench_ecmult.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ typedef struct {
secp256k1_ge* pubkeys;
secp256k1_scalar* seckeys;
secp256k1_gej* expected_output;
secp256k1_ecmult_multi_func ecmult_multi;

/* Changes per test */
size_t count;
Expand Down Expand Up @@ -63,7 +64,7 @@ static void bench_ecmult(void* arg) {
size_t iter;

for (iter = 0; iter < iters; ++iter) {
secp256k1_ecmult_multi_var(&data->ctx->ecmult_ctx, data->scratch, &data->output[iter], data->includes_g ? &data->scalars[data->offset1] : NULL, bench_callback, arg, count - includes_g);
data->ecmult_multi(&data->ctx->ecmult_ctx, data->scratch, &data->output[iter], data->includes_g ? &data->scalars[data->offset1] : NULL, bench_callback, arg, count - includes_g);
data->offset1 = (data->offset1 + count) % POINTS;
data->offset2 = (data->offset2 + count - 1) % POINTS;
}
Expand Down Expand Up @@ -136,10 +137,24 @@ int main(int argc, char **argv) {
bench_data data;
int i, p;
secp256k1_gej* pubkeys_gej;
size_t scratch_size;

if (argc > 1) {
if(have_flag(argc, argv, "pippenger_wnaf")) {
printf("Using pippenger_wnaf:\n");
data.ecmult_multi = secp256k1_ecmult_pippenger_batch_single;
} else if(have_flag(argc, argv, "strauss_wnaf")) {
printf("Using strauss_wnaf:\n");
data.ecmult_multi = secp256k1_ecmult_strauss_batch_single;
}
} else {
data.ecmult_multi = secp256k1_ecmult_multi_var;
}

/* Allocate stuff */
data.ctx = secp256k1_context_create(SECP256K1_CONTEXT_SIGN | SECP256K1_CONTEXT_VERIFY);
data.scratch = secp256k1_scratch_space_create(data.ctx, POINTS * 1024, POINTS * 5 * 1024);
scratch_size = secp256k1_strauss_scratch_size(POINTS) + STRAUSS_SCRATCH_OBJECTS*16;
data.scratch = secp256k1_scratch_space_create(data.ctx, scratch_size, scratch_size);
data.scalars = malloc(sizeof(secp256k1_scalar) * POINTS);
data.seckeys = malloc(sizeof(secp256k1_scalar) * POINTS);
data.pubkeys = malloc(sizeof(secp256k1_ge) * POINTS);
Expand Down
15 changes: 0 additions & 15 deletions src/bench_internal.c
Original file line number Diff line number Diff line change
Expand Up @@ -324,21 +324,6 @@ void bench_num_jacobi(void* arg) {
}
#endif

int have_flag(int argc, char** argv, char *flag) {
char** argm = argv + argc;
argv++;
if (argv == argm) {
return 1;
}
while (argv != NULL && argv != argm) {
if (strcmp(*argv, flag) == 0) {
return 1;
}
argv++;
}
return 0;
}

int main(int argc, char **argv) {
bench_inv data;
if (have_flag(argc, argv, "scalar") || have_flag(argc, argv, "add")) run_benchmark("scalar_add", bench_scalar_add, bench_setup, NULL, &data, 10, 2000000);
Expand Down

0 comments on commit a58f543

Please sign in to comment.