mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-05-16 08:54:19 +02:00
Note that `make_hard_case` already clears the UTXO pool in `coin_selection.cpp`. ./build/bin/bench_bitcoin -filter='^(BnBExhaustion|AddrManAddThenGood|DeserializeBlockTest|DeserializeAndCheckBlockTest|CheckBlockTest|LoadExternalBlockFile|FindByte|WalletCreatePlain|WalletCreateEncrypted|WalletLoadingDescriptors)$' | ns/op | op/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 15,088,500.00 | 66.28 | 0.2% | 0.17 | `AddrManAddThenGood` | 179,208.00 | 5,580.11 | 2.0% | 0.00 | `BnBExhaustion` | ns/block | block/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 318,166.00 | 3,143.01 | 3.5% | 0.00 | `CheckBlockTest` | 886,750.00 | 1,127.71 | 0.8% | 0.01 | `DeserializeBlockTest` | ns/op | op/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 42.00 | 23,809,523.81 | 2.4% | 0.00 | `FindByte` | 5,473,208.00 | 182.71 | 0.4% | 0.06 | `LoadExternalBlockFile` | 584,168,041.00 | 1.71 | 0.3% | 6.43 | `WalletCreateEncrypted` | 168,040,458.00 | 5.95 | 1.1% | 1.85 | `WalletCreatePlain` | 155,446,625.00 | 6.43 | 0.7% | 0.78 | `WalletLoadingDescriptors` | ns/op | op/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 14,894,917.00 | 67.14 | 0.3% | 0.16 | `AddrManAddThenGood` | 177,667.00 | 5,628.51 | 1.3% | 0.00 | `BnBExhaustion` | ns/block | block/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 313,791.00 | 3,186.83 | 3.8% | 0.00 | `CheckBlockTest` | 888,208.00 | 1,125.86 | 0.7% | 0.01 | `DeserializeBlockTest` | ns/op | op/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 41.00 | 24,390,243.90 | 2.4% | 0.00 | `FindByte` | 5,445,208.00 | 183.65 | 1.0% | 0.06 | `LoadExternalBlockFile` | 581,800,500.00 | 1.72 | 0.4% | 6.40 | `WalletCreateEncrypted` | 166,035,583.00 | 6.02 | 0.5% | 1.82 | `WalletCreatePlain` | 153,574,792.00 | 6.51 | 0.1% | 0.77 | `WalletLoadingDescriptors`
80 lines
2.9 KiB
C++
80 lines
2.9 KiB
C++
// Copyright (c) 2022-present The Bitcoin Core developers
|
|
// Distributed under the MIT software license, see the accompanying
|
|
// file COPYING or https://www.opensource.org/licenses/mit-license.php.
|
|
|
|
#include <bench/bench.h>
|
|
#include <bench/data/block413567.raw.h>
|
|
#include <chainparams.h>
|
|
#include <flatfile.h>
|
|
#include <node/blockstorage.h>
|
|
#include <span.h>
|
|
#include <streams.h>
|
|
#include <test/util/setup_common.h>
|
|
#include <uint256.h>
|
|
#include <util/fs.h>
|
|
#include <validation.h>
|
|
|
|
#include <cstdint>
|
|
#include <cstdio>
|
|
#include <map>
|
|
#include <memory>
|
|
#include <stdexcept>
|
|
#include <vector>
|
|
|
|
/**
|
|
* The LoadExternalBlockFile() function is used during -reindex and -loadblock.
|
|
*
|
|
* Create a test file that's similar to a datadir/blocks/blk?????.dat file,
|
|
* It contains around 134 copies of the same block (typical size of real block files).
|
|
* For each block in the file, LoadExternalBlockFile() won't find its parent,
|
|
* and so will skip the block. (In the real system, it will re-read the block
|
|
* from disk later when it encounters its parent.)
|
|
*
|
|
* This benchmark measures the performance of deserializing the block (or just
|
|
* its header, beginning with PR 16981).
|
|
*/
|
|
static void LoadExternalBlockFile(benchmark::Bench& bench)
|
|
{
|
|
const auto testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};
|
|
|
|
// Create a single block as in the blocks files (magic bytes, block size,
|
|
// block data) as a stream object.
|
|
const fs::path blkfile{testing_setup.get()->m_path_root / "blk.dat"};
|
|
DataStream ss{};
|
|
auto params{testing_setup->m_node.chainman->GetParams()};
|
|
ss << params.MessageStart();
|
|
ss << static_cast<uint32_t>(benchmark::data::block413567.size());
|
|
// Use span-serialization to avoid writing the size first.
|
|
ss << std::span{benchmark::data::block413567};
|
|
|
|
// Create the test file.
|
|
{
|
|
// "wb+" is "binary, O_RDWR | O_CREAT | O_TRUNC".
|
|
FILE* file{fsbridge::fopen(blkfile, "wb+")};
|
|
// Make the test block file about 128 MB in length.
|
|
for (size_t i = 0; i < node::MAX_BLOCKFILE_SIZE / ss.size(); ++i) {
|
|
if (fwrite(ss.data(), 1, ss.size(), file) != ss.size()) {
|
|
throw std::runtime_error("write to test file failed\n");
|
|
}
|
|
}
|
|
fclose(file);
|
|
}
|
|
|
|
std::multimap<uint256, FlatFilePos> blocks_with_unknown_parent;
|
|
FlatFilePos pos;
|
|
bench.epochIterations(1)
|
|
.setup([&] {
|
|
blocks_with_unknown_parent.clear();
|
|
pos = FlatFilePos{};
|
|
})
|
|
.run([&] {
|
|
// "rb" is "binary, O_RDONLY", positioned to the start of the file.
|
|
// The file will be closed by LoadExternalBlockFile().
|
|
AutoFile file{fsbridge::fopen(blkfile, "rb")};
|
|
testing_setup->m_node.chainman->LoadExternalBlockFile(file, &pos, &blocks_with_unknown_parent);
|
|
});
|
|
fs::remove(blkfile);
|
|
}
|
|
|
|
BENCHMARK(LoadExternalBlockFile);
|