Skip to content

Commit 0a6ee97

Browse files
committed
Merge #16267: bench: Benchmark blockToJSON
91509ff bench: Benchmark blockToJSON (Kirill Fomichev) Pull request description: Related: - "getblock performance issue on verbosity" bitcoin/bitcoin#15925 - "refactor: Avoid UniValue copy constructor" #15974 ACKs for top commit: laanwj: ACK 91509ff Tree-SHA512: e70b12cb31921c7527bde334f52f39776da698b6bbdb196079a8b68478c67585a5bd7bed7403f65166bd604f7ed60778c53dc064d743bb8368318a1283d1073e
2 parents 4882040 + 91509ff commit 0a6ee97

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

build_msvc/bench_bitcoin/bench_bitcoin.vcxproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
<ClCompile Include="..\..\src\bench\examples.cpp" />
2525
<ClCompile Include="..\..\src\bench\lockedpool.cpp" />
2626
<ClCompile Include="..\..\src\bench\mempool_eviction.cpp" />
27+
<ClCompile Include="..\..\src\bench\rpc_blockchain.cpp" />
2728
<ClCompile Include="..\..\src\bench\rpc_mempool.cpp" />
2829
<ClCompile Include="..\..\src\bench\merkle_root.cpp" />
2930
<ClCompile Include="..\..\src\bench\rollingbloom.cpp" />

src/Makefile.bench.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ bench_bench_bitcoin_SOURCES = \
2929
bench/gcs_filter.cpp \
3030
bench/merkle_root.cpp \
3131
bench/mempool_eviction.cpp \
32+
bench/rpc_blockchain.cpp \
3233
bench/rpc_mempool.cpp \
3334
bench/util_time.cpp \
3435
bench/verify_script.cpp \

src/bench/rpc_blockchain.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2016-2019 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+
8+
#include <validation.h>
9+
#include <streams.h>
10+
#include <consensus/validation.h>
11+
#include <rpc/blockchain.h>
12+
13+
#include <univalue.h>
14+
15+
static void BlockToJsonVerbose(benchmark::State& state) {
16+
CDataStream stream(benchmark::data::block413567, SER_NETWORK, PROTOCOL_VERSION);
17+
char a = '\0';
18+
stream.write(&a, 1); // Prevent compaction
19+
20+
CBlock block;
21+
stream >> block;
22+
23+
CBlockIndex blockindex;
24+
const uint256 blockHash = block.GetHash();
25+
blockindex.phashBlock = &blockHash;
26+
blockindex.nBits = 403014710;
27+
28+
while (state.KeepRunning()) {
29+
(void)blockToJSON(block, &blockindex, &blockindex, /*verbose*/ true);
30+
}
31+
}
32+
33+
BENCHMARK(BlockToJsonVerbose, 10);

0 commit comments

Comments
 (0)