Bitcoin Core  21.99.0
P2P Digital Currency
rpc_blockchain.cpp
Go to the documentation of this file.
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 #include <bench/data.h>
7 
8 #include <rpc/blockchain.h>
9 #include <streams.h>
10 #include <test/util/setup_common.h>
11 #include <validation.h>
12 
13 #include <univalue.h>
14 
15 namespace {
16 
17 struct TestBlockAndIndex {
18  const std::unique_ptr<const TestingSetup> testing_setup{MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN)};
19  CBlock block{};
20  uint256 blockHash{};
21  CBlockIndex blockindex{};
22 
23  TestBlockAndIndex()
24  {
26  char a = '\0';
27  stream.write(&a, 1); // Prevent compaction
28 
29  stream >> block;
30 
31  blockHash = block.GetHash();
32  blockindex.phashBlock = &blockHash;
33  blockindex.nBits = 403014710;
34  }
35 };
36 
37 } // namespace
38 
40 {
41  TestBlockAndIndex data;
42  bench.run([&] {
43  auto univalue = blockToJSON(data.block, &data.blockindex, &data.blockindex, /*verbose*/ true);
45  });
46 }
47 
49 
51 {
52  TestBlockAndIndex data;
53  auto univalue = blockToJSON(data.block, &data.blockindex, &data.blockindex, /*verbose*/ true);
54  bench.run([&] {
55  auto str = univalue.write();
57  });
58 }
59 
streams.h
BlockToJsonVerboseWrite
static void BlockToJsonVerboseWrite(benchmark::Bench &bench)
Definition: rpc_blockchain.cpp:50
BlockToJsonVerbose
static void BlockToJsonVerbose(benchmark::Bench &bench)
Definition: rpc_blockchain.cpp:39
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:583
benchmark::data::block413567
const std::vector< uint8_t > block413567
Definition: data.cpp:11
univalue.h
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1134
BENCHMARK
BENCHMARK(BlockToJsonVerbose)
uint256
256-bit opaque blob.
Definition: uint256.h:124
bench.h
CBaseChainParams::MAIN
static const std::string MAIN
Chain name strings.
Definition: chainparamsbase.h:22
CBlock
Definition: block.h:62
data.h
CDataStream
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:204
SER_NETWORK
@ SER_NETWORK
Definition: serialize.h:166
blockchain.h
CBlockIndex
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:137
blockToJSON
UniValue blockToJSON(const CBlock &block, const CBlockIndex *tip, const CBlockIndex *blockindex, bool txDetails)
Block description to JSON.
Definition: blockchain.cpp:171
PROTOCOL_VERSION
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:12
ankerl::nanobench::doNotOptimizeAway
void doNotOptimizeAway(Arg &&arg)
Makes sure none of the given arguments are optimized away by the compiler.
Definition: nanobench.h:1179