Bitcoin ABC  0.22.13
P2P Digital Currency
bench_multiset.c
Go to the documentation of this file.
1 /**********************************************************************
2  * Copyright (c) 2017 Tomas van der Wansem *
3  * Distributed under the MIT software license, see the accompanying *
4  * file COPYING or http://www.opensource.org/licenses/mit-license.php.*
5  **********************************************************************/
6 
7 #include "include/secp256k1.h"
9 #include "util.h"
10 #include "bench.h"
11 
13 
14 #define UNUSED(x) (void)(x)
15 
16 #define BUFSIZE (3 * 32)
17 
18 void bench_multiset(void* arg, int iters) {
19  int it = 0;
20  int n, m;
21  unsigned char result[32];
22  secp256k1_multiset multiset;
23 
24  UNUSED(arg);
25  secp256k1_multiset_init(ctx, &multiset);
26 
27  for (m = 0; m < iters; m++) {
28  unsigned char buf[BUFSIZE];
29  for (n = 0; n < BUFSIZE; n++) {
30  buf[n] = it++;
31  }
32 
33  secp256k1_multiset_add(ctx, &multiset, buf, sizeof(buf));
34  }
35 
36  secp256k1_multiset_finalize(ctx, result, &multiset);
37 }
38 
39 void bench_multiset_setup(void* arg) {
40  UNUSED(arg);
41 }
42 
43 int main(void) {
44  int iters = get_iters(300000);
45 
47  run_benchmark("multiset", bench_multiset, bench_multiset_setup, NULL, NULL, 5, iters);
49 
50  return 0;
51 }
void bench_multiset(void *arg, int iters)
secp256k1_context * ctx
void bench_multiset_setup(void *arg)
Opaque multiset; this is actually a group element.
#define UNUSED(x)
void run_benchmark(char *name, void(*benchmark)(void *, int), void(*setup)(void *), void(*teardown)(void *, int), void *data, int count, int iter)
Definition: bench.h:76
SECP256K1_API void secp256k1_context_destroy(secp256k1_context *ctx)
Destroy a secp256k1 context object (created in dynamically allocated memory).
Definition: secp256k1.c:197
#define BUFSIZE
SECP256K1_API int secp256k1_multiset_add(const secp256k1_context *ctx, secp256k1_multiset *multiset, const unsigned char *input, size_t inputLen) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Adds an element to a multiset from single data element.
Definition: main_impl.h:127
SECP256K1_API int secp256k1_multiset_finalize(const secp256k1_context *ctx, unsigned char *resultHash, const secp256k1_multiset *multiset) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2) SECP256K1_ARG_NONNULL(3)
Converts a multiset to a hash.
Definition: main_impl.h:165
#define SECP256K1_CONTEXT_VERIFY
Flags to pass to secp256k1_context_create, secp256k1_context_preallocated_size, and secp256k1_context...
Definition: secp256k1.h:170
SECP256K1_API int secp256k1_multiset_init(const secp256k1_context *ctx, secp256k1_multiset *multiset) SECP256K1_ARG_NONNULL(1) SECP256K1_ARG_NONNULL(2)
Initialize a multiset The resulting multiset the multiset for no data elements.
Definition: main_impl.h:200
int get_iters(int default_iters)
Definition: bench.h:124
int main(void)
SECP256K1_API secp256k1_context * secp256k1_context_create(unsigned int flags) SECP256K1_WARN_UNUSED_RESULT
Create a secp256k1 context object (in dynamically allocated memory).
Definition: secp256k1.c:153