Skip to content

Commit 52b803e

Browse files
committed
Merge #8107: bench: Added base58 encoding/decoding benchmarks
5fac1f3 bench: Added base58 encoding/decoding benchmarks (Yuri Zhykin)
2 parents 989df7e + 5fac1f3 commit 52b803e

File tree

2 files changed

+58
-1
lines changed

2 files changed

+58
-1
lines changed

src/Makefile.bench.include

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ bench_bench_bitcoin_SOURCES = \
99
bench/bench.h \
1010
bench/Examples.cpp \
1111
bench/rollingbloom.cpp \
12-
bench/crypto_hash.cpp
12+
bench/crypto_hash.cpp \
13+
bench/base58.cpp
1314

1415
bench_bench_bitcoin_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(EVENT_CLFAGS) $(EVENT_PTHREADS_CFLAGS) -I$(builddir)/bench/
1516
bench_bench_bitcoin_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)

src/bench/base58.cpp

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// Copyright (c) 2016 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.h"
6+
7+
#include "main.h"
8+
#include "base58.h"
9+
10+
#include <vector>
11+
#include <string>
12+
13+
14+
static void Base58Encode(benchmark::State& state)
15+
{
16+
unsigned char buff[32] = {
17+
17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203, 163, 36, 58, 147,
18+
227, 139, 2, 215, 100, 91, 38, 11, 141, 253, 40, 117, 21, 16, 90,
19+
200, 24
20+
};
21+
unsigned char* b = buff;
22+
while (state.KeepRunning()) {
23+
EncodeBase58(b, b + 32);
24+
}
25+
}
26+
27+
28+
static void Base58CheckEncode(benchmark::State& state)
29+
{
30+
unsigned char buff[32] = {
31+
17, 79, 8, 99, 150, 189, 208, 162, 22, 23, 203, 163, 36, 58, 147,
32+
227, 139, 2, 215, 100, 91, 38, 11, 141, 253, 40, 117, 21, 16, 90,
33+
200, 24
34+
};
35+
unsigned char* b = buff;
36+
std::vector<unsigned char> vch;
37+
vch.assign(b, b + 32);
38+
while (state.KeepRunning()) {
39+
EncodeBase58Check(vch);
40+
}
41+
}
42+
43+
44+
static void Base58Decode(benchmark::State& state)
45+
{
46+
const char* addr = "17VZNX1SN5NtKa8UQFxwQbFeFc3iqRYhem";
47+
std::vector<unsigned char> vch;
48+
while (state.KeepRunning()) {
49+
DecodeBase58(addr, vch);
50+
}
51+
}
52+
53+
54+
BENCHMARK(Base58Encode);
55+
BENCHMARK(Base58CheckEncode);
56+
BENCHMARK(Base58Decode);

0 commit comments

Comments
 (0)