Bitcoin Core 28.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
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.h>
7
8#include <rpc/blockchain.h>
9#include <streams.h>
11#include <util/chaintype.h>
12#include <validation.h>
13
14#include <univalue.h>
15
16namespace {
17
18struct TestBlockAndIndex {
19 const std::unique_ptr<const TestingSetup> testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
20 CBlock block{};
21 uint256 blockHash{};
22 CBlockIndex blockindex{};
23
24 TestBlockAndIndex()
25 {
27 std::byte a{0};
28 stream.write({&a, 1}); // Prevent compaction
29
30 stream >> TX_WITH_WITNESS(block);
31
32 blockHash = block.GetHash();
33 blockindex.phashBlock = &blockHash;
34 blockindex.nBits = 403014710;
35 }
36};
37
38} // namespace
39
41{
42 TestBlockAndIndex data;
43 bench.run([&] {
44 auto univalue = blockToJSON(data.testing_setup->m_node.chainman->m_blockman, data.block, data.blockindex, data.blockindex, TxVerbosity::SHOW_DETAILS_AND_PREVOUT);
46 });
47}
48
50
52{
53 TestBlockAndIndex data;
54 auto univalue = blockToJSON(data.testing_setup->m_node.chainman->m_blockman, data.block, data.blockindex, data.blockindex, TxVerbosity::SHOW_DETAILS_AND_PREVOUT);
55 bench.run([&] {
56 auto str = univalue.write();
58 });
59}
60
#define BENCHMARK(n, priority_level)
Definition bench.h:79
UniValue blockToJSON(BlockManager &blockman, const CBlock &block, const CBlockIndex &tip, const CBlockIndex &blockindex, TxVerbosity verbosity)
Block description to JSON.
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:178
@ 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
const std::vector< uint8_t > block413567
Definition data.cpp:11
@ HIGH
Definition bench.h:47
static constexpr TransactionSerParams TX_WITH_WITNESS
static void BlockToJsonVerbose(benchmark::Bench &bench)
static void BlockToJsonVerboseWrite(benchmark::Bench &bench)
std::unique_ptr< T > MakeNoLogFileContext(const ChainType chain_type=ChainType::REGTEST, TestOpts opts={})
Make a test setup that has disk access to the debug.log file disabled.