Bitcoin Core
32.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
bench
readwriteblock.cpp
Go to the documentation of this file.
1
// Copyright (c) 2023-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 <
flatfile.h
>
8
#include <
node/blockstorage.h
>
9
#include <
primitives/block.h
>
10
#include <
primitives/transaction.h
>
11
#include <
serialize.h
>
12
#include <
streams.h
>
13
#include <
sync.h
>
14
#include <
test/util/setup_common.h
>
15
#include <
util/check.h
>
16
#include <validation.h>
17
18
#include <memory>
19
#include <span>
20
21
static
CBlock
CreateTestBlock
()
22
{
23
CBlock
block;
24
SpanReader
{benchmark::data::block413567} >>
TX_WITH_WITNESS
(block);
25
return
block;
26
}
27
28
static
void
WriteBlockBench
(
benchmark::Bench
& bench)
29
{
30
const
auto
testing_setup{
MakeNoLogFileContext<const TestingSetup>
(
ChainType::MAIN
)};
31
auto
& blockman{testing_setup->m_node.chainman->m_blockman};
32
const
CBlock
block{
CreateTestBlock
()};
33
bench.
run
([&] {
34
LOCK
(
::cs_main
);
35
const
auto
pos{blockman.WriteBlock(block, 413'567)};
36
assert
(!pos.IsNull());
37
});
38
}
39
40
static
void
ReadBlockBench
(
benchmark::Bench
& bench)
41
{
42
const
auto
testing_setup{
MakeNoLogFileContext<const TestingSetup>
(
ChainType::MAIN
)};
43
auto
& blockman{testing_setup->m_node.chainman->m_blockman};
44
const
auto
& test_block{
CreateTestBlock
()};
45
const
auto
& expected_hash{test_block.GetHash()};
46
const
auto
& pos{
WITH_LOCK
(
::cs_main
,
return
blockman.WriteBlock(test_block, 413'567))};
47
bench.
run
([&] {
48
CBlock
block;
49
const
auto
success{blockman.ReadBlock(block, pos, expected_hash)};
50
assert
(success);
51
});
52
}
53
54
static
void
ReadRawBlockBench
(
benchmark::Bench
& bench)
55
{
56
const
auto
testing_setup{
MakeNoLogFileContext<const TestingSetup>
(
ChainType::MAIN
)};
57
auto
& blockman{testing_setup->m_node.chainman->m_blockman};
58
const
auto
pos{
WITH_LOCK
(
::cs_main
,
return
blockman.WriteBlock(
CreateTestBlock
(), 413'567))};
59
bench.
run
([&] {
60
const
auto
res{blockman.ReadRawBlock(pos)};
61
assert
(res);
62
});
63
}
64
65
BENCHMARK
(
WriteBlockBench
);
66
BENCHMARK
(
ReadBlockBench
);
67
BENCHMARK
(
ReadRawBlockBench
);
bench.h
BENCHMARK
#define BENCHMARK(n)
Definition
bench.h:69
block.h
blockstorage.h
ChainType::MAIN
@ MAIN
Definition
chaintype.h:13
check.h
CBlock
Definition
block.h:74
SpanReader
Minimal stream for reading from an existing byte array by std::span.
Definition
streams.h:83
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
CreateTestBlock
CBlock CreateTestBlock(TestChain100Setup &test_setup, const std::vector< CKey > &keys, const std::vector< CTxOut > &outputs, int num_txs=1000)
Definition
connectblock.cpp:36
cs_main
RecursiveMutex cs_main
Mutex to guard access to validation specific variables, such as reading or changing the chainstate.
Definition
cs_main.cpp:8
flatfile.h
transaction.h
TX_WITH_WITNESS
constexpr TransactionSerParams TX_WITH_WITNESS
Definition
transaction.h:181
ReadRawBlockBench
static void ReadRawBlockBench(benchmark::Bench &bench)
Definition
readwriteblock.cpp:54
WriteBlockBench
static void WriteBlockBench(benchmark::Bench &bench)
Definition
readwriteblock.cpp:28
ReadBlockBench
static void ReadBlockBench(benchmark::Bench &bench)
Definition
readwriteblock.cpp:40
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
sync.h
LOCK
#define LOCK(cs)
Definition
sync.h:268
WITH_LOCK
#define WITH_LOCK(cs, code)
Definition
sync.h:299
assert
assert(!tx.IsCoinBase())
Generated on
for Bitcoin Core by
1.18.0