Bitcoin ABC  0.26.3
P2P Digital Currency
rpc_blockchain.cpp
Go to the documentation of this file.
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 <rpc/blockchain.h>
9 #include <streams.h>
10 #include <validation.h>
11 
12 #include <test/util/setup_common.h>
13 
14 #include <univalue.h>
15 
16 namespace {
17 
18 struct TestBlockAndIndex {
19  TestingSetup test_setup{};
20  CBlock block{};
21  BlockHash blockHash{};
22  CBlockIndex blockindex{};
23 
24  TestBlockAndIndex() {
27  char a = '\0';
28  // Prevent compaction
29  stream.write(&a, 1);
30 
31  stream >> block;
32 
33  blockHash = block.GetHash();
34  blockindex.phashBlock = &blockHash;
35  blockindex.nBits = 403014710;
36  }
37 };
38 
39 } // namespace
40 
41 static void BlockToJsonVerbose(benchmark::Bench &bench) {
42  TestBlockAndIndex data;
43  bench.run([&] {
44  auto univalue =
45  blockToJSON(data.test_setup.m_node.chainman->m_blockman, data.block,
46  &data.blockindex, &data.blockindex, /*txDetails=*/true);
48  });
49 }
50 
52 
54  TestBlockAndIndex data;
55  auto univalue = blockToJSON(data.test_setup.m_node.chainman->m_blockman,
56  data.block, &data.blockindex, &data.blockindex,
57  /*txDetails=*/true);
58  bench.run([&] {
59  auto str = univalue.write();
61  });
62 }
63 
UniValue blockToJSON(BlockManager &blockman, const CBlock &block, const CBlockIndex *tip, const CBlockIndex *blockindex, bool txDetails)
Block description to JSON.
Definition: blockchain.cpp:167
Definition: block.h:55
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: blockindex.h:26
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:197
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:616
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1183
void doNotOptimizeAway(Arg &&arg)
Makes sure none of the given arguments are optimized away by the compiler.
Definition: nanobench.h:1228
const std::vector< uint8_t > block413567
Definition: data.cpp:11
static void BlockToJsonVerbose(benchmark::Bench &bench)
BENCHMARK(BlockToJsonVerbose)
static void BlockToJsonVerboseWrite(benchmark::Bench &bench)
@ SER_NETWORK
Definition: serialize.h:166
A BlockHash is a unqiue identifier for a block.
Definition: blockhash.h:13
static const int PROTOCOL_VERSION
network protocol versioning
Definition: version.h:11