Skip to content

Commit 9a5cebc

Browse files
committed
Bench tests for CPubKey<->EllSq
1 parent 9e432fe commit 9a5cebc

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/Makefile.bench.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ bench_bench_bitcoin_SOURCES = \
2222
bench/data.h \
2323
bench/data.cpp \
2424
bench/duplicate_inputs.cpp \
25+
bench/ellsq.cpp \
2526
bench/examples.cpp \
2627
bench/rollingbloom.cpp \
2728
bench/chacha20.cpp \

src/bench/ellsq.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (c) 2016-2020 The Bitcoin Core developers
2+
// Distributed under the MIT software license, see the accompanying
3+
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4+
5+
#include <bench/bench.h>
6+
7+
#include <pubkey.h>
8+
#include <random.h>
9+
10+
#include <array>
11+
12+
EllSqPubKey GetRandomEllSq() {
13+
EllSqPubKey encoded_pubkey;
14+
15+
// GetRandBytes can only give us up to 32 bytes at a time
16+
GetRandBytes(encoded_pubkey.data(), 32);
17+
GetRandBytes(encoded_pubkey.data() + 32, 32);
18+
19+
return encoded_pubkey;
20+
}
21+
22+
static void EllSqEncode(benchmark::Bench& bench)
23+
{
24+
std::array<uint8_t, 32> rnd32;
25+
GetRandBytes(rnd32.data(), 32);
26+
27+
// Any 64 bytes are a valid encoding for a public key.
28+
EllSqPubKey encoded_pubkey = GetRandomEllSq();
29+
CPubKey pubkey{encoded_pubkey};
30+
bench.batch(1).unit("pubkey").run([&] {
31+
pubkey.EllSqEncode(rnd32);
32+
});
33+
}
34+
35+
static void EllSqDecode(benchmark::Bench& bench)
36+
{
37+
// Any 64 bytes are a valid encoding for a public key.
38+
EllSqPubKey encoded_pubkey = GetRandomEllSq();
39+
bench.batch(1).unit("pubkey").run([&] {
40+
CPubKey pubkey{encoded_pubkey};
41+
});
42+
}
43+
44+
BENCHMARK(EllSqEncode);
45+
BENCHMARK(EllSqDecode);

0 commit comments

Comments
 (0)