Skip to content

Commit

Permalink
Merge branch 'backport/core-pr16267' into 'master'
Browse files Browse the repository at this point in the history
bench: Benchmark blockToJSON

See merge request bitcoin-cash-node/bitcoin-cash-node!97
  • Loading branch information
ftrader committed Mar 12, 2020
2 parents 76ef8f0 + 822e0ff commit a4a992b
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Makefile.bench.include
Expand Up @@ -29,6 +29,7 @@ bench_bench_bitcoin_SOURCES = \
bench/gcs_filter.cpp \
bench/merkle_root.cpp \
bench/mempool_eviction.cpp \
bench/rpc_blockchain.cpp \
bench/rpc_mempool.cpp \
bench/base58.cpp \
bench/lockedpool.cpp \
Expand Down
1 change: 1 addition & 0 deletions src/bench/CMakeLists.txt
Expand Up @@ -54,6 +54,7 @@ add_executable(bitcoin-bench
merkle_root.cpp
prevector.cpp
rollingbloom.cpp
rpc_blockchain.cpp
rpc_mempool.cpp

# Add the generated headers to trigger the conversion command
Expand Down
37 changes: 37 additions & 0 deletions src/bench/rpc_blockchain.cpp
@@ -0,0 +1,37 @@
// Copyright (c) 2016-2019 The Bitcoin Core developers
// Copyright (c) 2020 The Bitcoin developers
// Distributed under the MIT software license, see the accompanying
// file COPYING or http://www.opensource.org/licenses/mit-license.php.

#include <bench/bench.h>
#include <bench/data.h>

#include <chainparams.h>
#include <validation.h>
#include <streams.h>
#include <consensus/validation.h>
#include <rpc/blockchain.h>

#include <univalue.h>

static void BlockToJsonVerbose(benchmark::State& state) {
SelectParams(CBaseChainParams::MAIN);

CDataStream stream(benchmark::data::block413567, SER_NETWORK, PROTOCOL_VERSION);
char a = '\0';
stream.write(&a, 1); // Prevent compaction

CBlock block;
stream >> block;

CBlockIndex blockindex;
const auto blockHash = block.GetHash();
blockindex.phashBlock = &blockHash;
blockindex.nBits = 403014710;

while (state.KeepRunning()) {
(void)blockToJSON(block, &blockindex, &blockindex, /*verbose*/ true);
}
}

BENCHMARK(BlockToJsonVerbose, 10);

0 comments on commit a4a992b

Please sign in to comment.