aboutsummaryrefslogtreecommitdiff
path: root/src/bench
diff options
context:
space:
mode:
authorAndrew Toth <andrewstoth@gmail.com>2023-08-07 10:15:26 -0400
committerAndrew Toth <andrewstoth@gmail.com>2023-11-26 13:24:05 -0500
commit1c4b9cbe906507295d8b7d52855de1441ad411dd (patch)
treed7935cd03af0672ac78faff05cac1fa61a1e91ef /src/bench
parent5f9fd11680af43b0d0d80a6aa4f315aa04afeac4 (diff)
bench: add readblock benchmark
Diffstat (limited to 'src/bench')
-rw-r--r--src/bench/readblock.cpp53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/bench/readblock.cpp b/src/bench/readblock.cpp
new file mode 100644
index 0000000000..0545c6b017
--- /dev/null
+++ b/src/bench/readblock.cpp
@@ -0,0 +1,53 @@
+// Copyright (c) 2023 The Bitcoin Core developers
+// Distributed under the MIT software license, see the accompanying
+// file COPYING or http://www.opensource.org/licenses/mit-license.php.
+
+#include <bench/bench.h>
+#include <bench/data.h>
+
+#include <consensus/validation.h>
+#include <node/blockstorage.h>
+#include <streams.h>
+#include <test/util/setup_common.h>
+#include <util/chaintype.h>
+#include <validation.h>
+
+static FlatFilePos WriteBlockToDisk(ChainstateManager& chainman)
+{
+ DataStream stream{benchmark::data::block413567};
+ CBlock block;
+ stream >> TX_WITH_WITNESS(block);
+
+ return chainman.m_blockman.SaveBlockToDisk(block, 0, nullptr);
+}
+
+static void ReadBlockFromDiskTest(benchmark::Bench& bench)
+{
+ const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
+ ChainstateManager& chainman{*testing_setup->m_node.chainman};
+
+ CBlock block;
+ const auto pos{WriteBlockToDisk(chainman)};
+
+ bench.run([&] {
+ const auto success{chainman.m_blockman.ReadBlockFromDisk(block, pos)};
+ assert(success);
+ });
+}
+
+static void ReadRawBlockFromDiskTest(benchmark::Bench& bench)
+{
+ const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
+ ChainstateManager& chainman{*testing_setup->m_node.chainman};
+
+ std::vector<uint8_t> block_data;
+ const auto pos{WriteBlockToDisk(chainman)};
+
+ bench.run([&] {
+ const auto success{chainman.m_blockman.ReadRawBlockFromDisk(block_data, pos)};
+ assert(success);
+ });
+}
+
+BENCHMARK(ReadBlockFromDiskTest, benchmark::PriorityLevel::HIGH);
+BENCHMARK(ReadRawBlockFromDiskTest, benchmark::PriorityLevel::HIGH);