|
| 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