Bitcoin Core 28.99.0
P2P Digital Currency
rpc_blockchain.cpp
Go to the documentation of this file.
1// Copyright (c) 2016-2022 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/block413567.raw.h>
7#include <chain.h>
8#include <core_io.h>
9#include <primitives/block.h>
11#include <rpc/blockchain.h>
12#include <serialize.h>
13#include <span.h>
14#include <streams.h>
16#include <uint256.h>
17#include <univalue.h>
18#include <validation.h>
19
20#include <cstddef>
21#include <memory>
22#include <vector>
23
24namespace {
25
26struct TestBlockAndIndex {
27 const std::unique_ptr<const TestingSetup> testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
28 CBlock block{};
29 uint256 blockHash{};
30 CBlockIndex blockindex{};
31
32 TestBlockAndIndex()
33 {
34 DataStream stream{benchmark::data::block413567};
35 std::byte a{0};
36 stream.write({&a, 1}); // Prevent compaction
37
38 stream >> TX_WITH_WITNESS(block);
39
40 blockHash = block.GetHash();
41 blockindex.phashBlock = &blockHash;
42 blockindex.nBits = 403014710;
43 }
44};
45
46} // namespace
47
49{
50 TestBlockAndIndex data;
51 bench.run([&] {
52 auto univalue = blockToJSON(data.testing_setup->m_node.chainman->m_blockman, data.block, data.blockindex, data.blockindex, TxVerbosity::SHOW_DETAILS_AND_PREVOUT);
54 });
55}
56
58
60{
61 TestBlockAndIndex data;
62 auto univalue = blockToJSON(data.testing_setup->m_node.chainman->m_blockman, data.block, data.blockindex, data.blockindex, TxVerbosity::SHOW_DETAILS_AND_PREVOUT);
63 bench.run([&] {
64 auto str = univalue.write();
66 });
67}
68
UniValue blockToJSON(BlockManager &blockman, const CBlock &block, const CBlockIndex &tip, const CBlockIndex &blockindex, TxVerbosity verbosity)
Block description to JSON.
Definition: blockchain.cpp:178
Definition: block.h:69
The block chain is a tree shaped structure starting with the genesis block at the root,...
Definition: chain.h:141
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:147
void write(Span< const value_type > src)
Definition: streams.h:251
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:627
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1234
256-bit opaque blob.
Definition: uint256.h:190
@ SHOW_DETAILS_AND_PREVOUT
The same as previous option with information about prevouts if available.
void doNotOptimizeAway(Arg &&arg)
Makes sure none of the given arguments are optimized away by the compiler.
Definition: nanobench.h:1279
@ HIGH
Definition: bench.h:48
static constexpr TransactionSerParams TX_WITH_WITNESS
Definition: transaction.h:195
static void BlockToJsonVerbose(benchmark::Bench &bench)
static void BlockToJsonVerboseWrite(benchmark::Bench &bench)
BENCHMARK(BlockToJsonVerbose, benchmark::PriorityLevel::HIGH)