Skip to content

Commit 1c4b9cb

Browse files
committed
bench: add readblock benchmark
1 parent 5f9fd11 commit 1c4b9cb

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed

src/Makefile.bench.include

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ bench_bench_bitcoin_SOURCES = \
4646
bench/poly1305.cpp \
4747
bench/pool.cpp \
4848
bench/prevector.cpp \
49+
bench/readblock.cpp \
4950
bench/rollingbloom.cpp \
5051
bench/rpc_blockchain.cpp \
5152
bench/rpc_mempool.cpp \

src/bench/readblock.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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 <consensus/validation.h>
9+
#include <node/blockstorage.h>
10+
#include <streams.h>
11+
#include <test/util/setup_common.h>
12+
#include <util/chaintype.h>
13+
#include <validation.h>
14+
15+
static FlatFilePos WriteBlockToDisk(ChainstateManager& chainman)
16+
{
17+
DataStream stream{benchmark::data::block413567};
18+
CBlock block;
19+
stream >> TX_WITH_WITNESS(block);
20+
21+
return chainman.m_blockman.SaveBlockToDisk(block, 0, nullptr);
22+
}
23+
24+
static void ReadBlockFromDiskTest(benchmark::Bench& bench)
25+
{
26+
const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
27+
ChainstateManager& chainman{*testing_setup->m_node.chainman};
28+
29+
CBlock block;
30+
const auto pos{WriteBlockToDisk(chainman)};
31+
32+
bench.run([&] {
33+
const auto success{chainman.m_blockman.ReadBlockFromDisk(block, pos)};
34+
assert(success);
35+
});
36+
}
37+
38+
static void ReadRawBlockFromDiskTest(benchmark::Bench& bench)
39+
{
40+
const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
41+
ChainstateManager& chainman{*testing_setup->m_node.chainman};
42+
43+
std::vector<uint8_t> block_data;
44+
const auto pos{WriteBlockToDisk(chainman)};
45+
46+
bench.run([&] {
47+
const auto success{chainman.m_blockman.ReadRawBlockFromDisk(block_data, pos)};
48+
assert(success);
49+
});
50+
}
51+
52+
BENCHMARK(ReadBlockFromDiskTest, benchmark::PriorityLevel::HIGH);
53+
BENCHMARK(ReadRawBlockFromDiskTest, benchmark::PriorityLevel::HIGH);

0 commit comments

Comments
 (0)