You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bench_inv.c 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /**********************************************************************
  2. * Copyright (c) 2014 Pieter Wuille *
  3. * Distributed under the MIT software license, see the accompanying *
  4. * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
  5. **********************************************************************/
  6. #include <stdio.h>
  7. #include "include/secp256k1.h"
  8. #include "util.h"
  9. #include "num_impl.h"
  10. #include "field_impl.h"
  11. #include "group_impl.h"
  12. #include "scalar_impl.h"
  13. #include "bench.h"
  14. typedef struct {
  15. secp256k1_scalar_t base, x;
  16. } bench_inv_t;
  17. void bench_inv_setup(void* arg) {
  18. bench_inv_t *data = (bench_inv_t*)arg;
  19. static const unsigned char init[32] = {
  20. 0x02, 0x03, 0x05, 0x07, 0x0b, 0x0d, 0x11, 0x13,
  21. 0x17, 0x1d, 0x1f, 0x25, 0x29, 0x2b, 0x2f, 0x35,
  22. 0x3b, 0x3d, 0x43, 0x47, 0x49, 0x4f, 0x53, 0x59,
  23. 0x61, 0x65, 0x67, 0x6b, 0x6d, 0x71, 0x7f, 0x83
  24. };
  25. secp256k1_scalar_set_b32(&data->base, init, NULL);
  26. secp256k1_scalar_set_b32(&data->x, init, NULL);
  27. }
  28. void bench_inv(void* arg) {
  29. bench_inv_t *data = (bench_inv_t*)arg;
  30. for (int i=0; i<20000; i++) {
  31. secp256k1_scalar_inverse(&data->x, &data->x);
  32. secp256k1_scalar_add(&data->x, &data->x, &data->base);
  33. }
  34. }
  35. int main(void) {
  36. secp256k1_ge_start();
  37. bench_inv_t data;
  38. run_benchmark(bench_inv, bench_inv_setup, NULL, &data, 10, 20000);
  39. secp256k1_ge_stop();
  40. return 0;
  41. }