Bitcoin Core 28.99.0
P2P Digital Currency
readwriteblock.cpp
Go to the documentation of this file.
1// Copyright (c) 2023 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>
11#include <serialize.h>
12#include <span.h>
13#include <streams.h>
15#include <validation.h>
16
17#include <cassert>
18#include <cstdint>
19#include <memory>
20#include <vector>
21
23{
24 DataStream stream{benchmark::data::block413567};
25 CBlock block;
26 stream >> TX_WITH_WITNESS(block);
27 return block;
28}
29
31{
32 const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
33 auto& blockman{testing_setup->m_node.chainman->m_blockman};
34 const CBlock block{CreateTestBlock()};
35 bench.run([&] {
36 const auto pos{blockman.WriteBlock(block, 413'567)};
37 assert(!pos.IsNull());
38 });
39}
40
42{
43 const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
44 auto& blockman{testing_setup->m_node.chainman->m_blockman};
45 const auto pos{blockman.WriteBlock(CreateTestBlock(), 413'567)};
46 CBlock block;
47 bench.run([&] {
48 const auto success{blockman.ReadBlock(block, pos)};
49 assert(success);
50 });
51}
52
54{
55 const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
56 auto& blockman{testing_setup->m_node.chainman->m_blockman};
57 const auto pos{blockman.WriteBlock(CreateTestBlock(), 413'567)};
58 std::vector<uint8_t> block_data;
59 blockman.ReadRawBlock(block_data, pos); // warmup
60 bench.run([&] {
61 const auto success{blockman.ReadRawBlock(block_data, pos)};
62 assert(success);
63 });
64}
65
Definition: block.h:69
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:147
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
@ HIGH
Definition: bench.h:48
static constexpr TransactionSerParams TX_WITH_WITNESS
Definition: transaction.h:195
static CBlock CreateTestBlock()
static void SaveBlockBench(benchmark::Bench &bench)
static void ReadRawBlockBench(benchmark::Bench &bench)
BENCHMARK(SaveBlockBench, benchmark::PriorityLevel::HIGH)
static void ReadBlockBench(benchmark::Bench &bench)
assert(!tx.IsCoinBase())