Bitcoin ABC 0.32.6
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.h>
7
8#include <flatfile.h>
9#include <node/blockstorage.h>
10#include <primitives/block.h>
11#include <serialize.h>
12#include <span.h>
13#include <streams.h>
14#include <test/util/setup_common.h>
15#include <validation.h>
16
17#include <cassert>
18#include <cstdint>
19#include <memory>
20#include <vector>
21
24 CBlock block;
25 stream >> block;
26 return block;
27}
28
29static void WriteBlockBench(benchmark::Bench &bench) {
30 const auto testing_setup{
31 MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
32 auto &blockman{testing_setup->m_node.chainman->m_blockman};
33 const CBlock block{CreateTestBlock()};
34 bench.run([&] {
35 const auto pos{blockman.WriteBlock(block, 413'567)};
36 assert(!pos.IsNull());
37 });
38}
39
40static void ReadBlockBench(benchmark::Bench &bench) {
41 const auto testing_setup{
42 MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
43 auto &blockman{testing_setup->m_node.chainman->m_blockman};
44 const auto pos{blockman.WriteBlock(CreateTestBlock(), 413'567)};
45 CBlock block;
46 bench.run([&] {
47 const auto success{blockman.ReadBlock(block, pos)};
48 assert(success);
49 });
50}
51
53 const auto testing_setup{
54 MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
55
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 // warmup
60 blockman.ReadRawBlock(block_data, pos);
61 bench.run([&] {
62 const auto success{blockman.ReadRawBlock(block_data, pos)};
63 assert(success);
64 });
65}
66
Definition: block.h:60
Double ended buffer combining vector and stream-like interfaces.
Definition: streams.h:118
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:616
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1183
const std::vector< uint8_t > block413567
Definition: data.cpp:11
static CBlock CreateTestBlock()
BENCHMARK(WriteBlockBench)
static void ReadRawBlockBench(benchmark::Bench &bench)
static void WriteBlockBench(benchmark::Bench &bench)
static void ReadBlockBench(benchmark::Bench &bench)
assert(!tx.IsCoinBase())