Skip to content

Commit 4e2b99f

Browse files
committed
bench: Adds a benchmark for HexStr
Benchmarks conversion of a full binary block into hex, like it is done in rest.cpp.
1 parent 67c8411 commit 4e2b99f

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/Makefile.bench.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ bench_bench_bitcoin_SOURCES = \
4444
bench/rollingbloom.cpp \
4545
bench/rpc_blockchain.cpp \
4646
bench/rpc_mempool.cpp \
47+
bench/strencodings.cpp \
4748
bench/util_time.cpp \
4849
bench/verify_script.cpp
4950

src/bench/strencodings.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2022 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+
#include <bench/data.h>
7+
#include <util/strencodings.h>
8+
9+
static void HexStrBench(benchmark::Bench& bench)
10+
{
11+
auto const& data = benchmark::data::block413567;
12+
bench.batch(data.size()).unit("byte").run([&] {
13+
auto hex = HexStr(data);
14+
ankerl::nanobench::doNotOptimizeAway(hex);
15+
});
16+
}
17+
18+
BENCHMARK(HexStrBench);

0 commit comments

Comments
 (0)