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  const std::unique_ptr<const TestingSetup> testing_setup{
20  MakeNoLogFileContext<const TestingSetup>(CBaseChainParams::MAIN)};
21  CBlock block{};
22  BlockHash blockHash{};
23  CBlockIndex blockindex{};
24 
25  TestBlockAndIndex() {
28  std::byte a{0};
29  // Prevent compaction
30  stream.write({&a, 1});
31 
32  stream >> block;
33 
34  blockHash = block.GetHash();
35  blockindex.phashBlock = &blockHash;
36  blockindex.nBits = 403014710;
37  }
38 };
39 
40 } // namespace
41 
42 static void BlockToJsonVerbose(benchmark::Bench &bench) {
43  TestBlockAndIndex data;
44  bench.run([&] {
45  auto univalue = blockToJSON(
46  data.testing_setup->m_node.chainman->m_blockman, data.block,
47  &data.blockindex, &data.blockindex, /*txDetails=*/true);
49  });
50 }
51 
53 
55  TestBlockAndIndex data;
56  auto univalue = blockToJSON(data.testing_setup->m_node.chainman->m_blockman,
57  data.block, &data.blockindex, &data.blockindex,
58  /*txDetails=*/true);
59  bench.run([&] {
60  auto str = univalue.write();
62  });
63 }
64 
UniValue blockToJSON(BlockManager &blockman, const CBlock &block, const CBlockIndex *tip, const CBlockIndex *blockindex, bool txDetails)
Block description to JSON.
Definition: blockchain.cpp:165
static const std::string MAIN
BIP70 chain name strings (main, test or regtest)
Definition: block.h:60
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:177
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:152
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