Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
bench
rpc_blockchain.cpp
Go to the documentation of this file.
1
// Copyright (c) 2016-present 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 <
consensus/params.h
>
9
#include <
core_io.h
>
10
#include <
kernel/chainparams.h
>
11
#include <
primitives/block.h
>
12
#include <
primitives/transaction.h
>
13
#include <
rpc/blockchain.h
>
14
#include <
serialize.h
>
15
#include <
streams.h
>
16
#include <
test/util/setup_common.h
>
17
#include <
uint256.h
>
18
#include <
univalue.h
>
19
#include <validation.h>
20
21
#include <memory>
22
#include <span>
23
#include <string>
24
25
namespace
{
26
27
struct
TestBlockAndIndex {
28
const
std::unique_ptr<const TestingSetup> testing_setup{
MakeNoLogFileContext<const TestingSetup>
(
ChainType::MAIN
)};
29
CBlock block{};
30
uint256 blockHash{};
31
CBlockIndex blockindex{};
32
33
TestBlockAndIndex()
34
{
35
SpanReader stream{benchmark::data::block413567};
36
stream >>
TX_WITH_WITNESS
(block);
37
38
blockHash = block.GetHash();
39
blockindex.phashBlock = &blockHash;
40
blockindex.nBits = 403014710;
41
}
42
};
43
44
}
// namespace
45
46
static
void
BlockToJson
(
benchmark::Bench
& bench,
TxVerbosity
verbosity)
47
{
48
TestBlockAndIndex data;
49
const
uint256
pow_limit{data.testing_setup->m_node.chainman->GetParams().GetConsensus().powLimit};
50
bench.
run
([&] {
51
auto
univalue =
blockToJSON
(data.testing_setup->m_node.chainman->m_blockman, data.block, data.blockindex, data.blockindex, verbosity, pow_limit);
52
ankerl::nanobench::doNotOptimizeAway
(univalue);
53
});
54
}
55
56
static
void
BlockToJsonVerbosity1
(
benchmark::Bench
& bench)
57
{
58
BlockToJson
(bench,
TxVerbosity::SHOW_TXID
);
59
}
60
61
static
void
BlockToJsonVerbosity2
(
benchmark::Bench
& bench)
62
{
63
BlockToJson
(bench,
TxVerbosity::SHOW_DETAILS
);
64
}
65
66
static
void
BlockToJsonVerbosity3
(
benchmark::Bench
& bench)
67
{
68
BlockToJson
(bench,
TxVerbosity::SHOW_DETAILS_AND_PREVOUT
);
69
}
70
71
BENCHMARK
(
BlockToJsonVerbosity1
);
72
BENCHMARK
(
BlockToJsonVerbosity2
);
73
BENCHMARK
(
BlockToJsonVerbosity3
);
74
75
static
void
BlockToJsonVerboseWrite
(
benchmark::Bench
& bench)
76
{
77
TestBlockAndIndex data;
78
const
uint256
pow_limit{data.testing_setup->m_node.chainman->GetParams().GetConsensus().powLimit};
79
auto
univalue =
blockToJSON
(data.testing_setup->m_node.chainman->m_blockman, data.block, data.blockindex, data.blockindex,
TxVerbosity::SHOW_DETAILS_AND_PREVOUT
, pow_limit);
80
bench.
run
([&] {
81
auto
str = univalue.write();
82
ankerl::nanobench::doNotOptimizeAway
(str);
83
});
84
}
85
86
BENCHMARK
(
BlockToJsonVerboseWrite
);
bench.h
BENCHMARK
#define BENCHMARK(n)
Definition
bench.h:69
block.h
blockToJSON
UniValue blockToJSON(BlockManager &blockman, const CBlock &block, const CBlockIndex &tip, const CBlockIndex &blockindex, TxVerbosity verbosity, const uint256 pow_limit)
Block description to JSON.
Definition
blockchain.cpp:242
blockchain.h
ChainType::MAIN
@ MAIN
Definition
chaintype.h:13
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition
nanobench.h:649
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition
nanobench.h:1308
uint256
256-bit opaque blob.
Definition
uint256.h:196
core_io.h
TxVerbosity
TxVerbosity
Verbose level for block's transaction.
Definition
core_io.h:29
TxVerbosity::SHOW_DETAILS_AND_PREVOUT
@ SHOW_DETAILS_AND_PREVOUT
The same as previous option with information about prevouts if available.
Definition
core_io.h:32
TxVerbosity::SHOW_TXID
@ SHOW_TXID
Only TXID for each block's transaction.
Definition
core_io.h:30
TxVerbosity::SHOW_DETAILS
@ SHOW_DETAILS
Include TXID, inputs, outputs, and other common block's transaction information.
Definition
core_io.h:31
chainparams.h
ankerl::nanobench::doNotOptimizeAway
void doNotOptimizeAway(Arg &&arg)
Makes sure none of the given arguments are optimized away by the compiler.
Definition
nanobench.h:1353
params.h
transaction.h
TX_WITH_WITNESS
constexpr TransactionSerParams TX_WITH_WITNESS
Definition
transaction.h:181
BlockToJsonVerbosity2
static void BlockToJsonVerbosity2(benchmark::Bench &bench)
Definition
rpc_blockchain.cpp:61
BlockToJson
static void BlockToJson(benchmark::Bench &bench, TxVerbosity verbosity)
Definition
rpc_blockchain.cpp:46
BlockToJsonVerbosity1
static void BlockToJsonVerbosity1(benchmark::Bench &bench)
Definition
rpc_blockchain.cpp:56
BlockToJsonVerboseWrite
static void BlockToJsonVerboseWrite(benchmark::Bench &bench)
Definition
rpc_blockchain.cpp:75
BlockToJsonVerbosity3
static void BlockToJsonVerbosity3(benchmark::Bench &bench)
Definition
rpc_blockchain.cpp:66
serialize.h
setup_common.h
MakeNoLogFileContext
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.
Definition
setup_common.h:241
streams.h
uint256.h
univalue.h
Generated on
for Bitcoin Core by
1.18.0