Skip to content

Commit 505797e

Browse files
committed
Bench tests for CPubKey<->EllSq
1 parent d210332 commit 505797e

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/Makefile.bench.include

+1
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

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
{
14+
EllSqPubKey encoded_pubkey;
15+
16+
// GetRandBytes can only give us up to 32 bytes at a time
17+
GetRandBytes(encoded_pubkey.data(), 32);
18+
GetRandBytes(encoded_pubkey.data() + 32, 32);
19+
20+
return encoded_pubkey;
21+
}
22+
23+
static void EllSqEncode(benchmark::Bench& bench)
24+
{
25+
std::array<uint8_t, 32> rnd32;
26+
GetRandBytes(rnd32.data(), 32);
27+
28+
// Any 64 bytes are a valid encoding for a public key.
29+
EllSqPubKey encoded_pubkey = GetRandomEllSq();
30+
CPubKey pubkey{encoded_pubkey};
31+
bench.batch(1).unit("pubkey").run([&] {
32+
pubkey.EllSqEncode(rnd32);
33+
});
34+
}
35+
36+
static void EllSqDecode(benchmark::Bench& bench)
37+
{
38+
// Any 64 bytes are a valid encoding for a public key.
39+
EllSqPubKey encoded_pubkey = GetRandomEllSq();
40+
bench.batch(1).unit("pubkey").run([&] {
41+
CPubKey pubkey{encoded_pubkey};
42+
});
43+
}
44+
45+
BENCHMARK(EllSqEncode);
46+
BENCHMARK(EllSqDecode);

0 commit comments

Comments
 (0)