mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-29 14:59:39 -04:00
> cmake -B build -DBUILD_BENCH=ON -DCMAKE_BUILD_TYPE=Release && cmake --build build -j$(nproc) && build/src/bench/bench_bitcoin -filter='CheckBlockBench|DuplicateInputs' -min-time=10000 > C++ compiler .......................... AppleClang 16.0.0.16000026 | ns/block | block/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 372,743.63 | 2,682.81 | 1.1% | 10.99 | `CheckBlockBench` | ns/op | op/s | err% | total | benchmark |--------------------:|--------------------:|--------:|----------:|:---------- | 3,304,694.54 | 302.60 | 0.5% | 11.05 | `DuplicateInputs` > C++ compiler .......................... GNU 13.3.0 | ns/block | block/s | err% | ins/block | cyc/block | IPC | bra/block | miss% | total | benchmark |--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:---------- | 1,096,261.84 | 912.19 | 0.1% | 7,963,390.88 | 3,487,375.26 | 2.283 | 1,266,941.00 | 1.8% | 11.03 | `CheckBlockBench` | ns/op | op/s | err% | ins/op | cyc/op | IPC | bra/op | miss% | total | benchmark |--------------------:|--------------------:|--------:|----------------:|----------------:|-------:|---------------:|--------:|----------:|:---------- | 8,366,309.48 | 119.53 | 0.0% | 23,865,177.67 | 26,620,160.23 | 0.897 | 5,972,887.41 | 4.0% | 10.78 | `DuplicateInputs`
89 lines
3 KiB
C++
89 lines
3 KiB
C++
// Copyright (c) 2016-2022 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/block413567.raw.h>
|
|
#include <chainparams.h>
|
|
#include <common/args.h>
|
|
#include <consensus/validation.h>
|
|
#include <primitives/block.h>
|
|
#include <primitives/transaction.h>
|
|
#include <serialize.h>
|
|
#include <span.h>
|
|
#include <streams.h>
|
|
#include <util/chaintype.h>
|
|
#include <validation.h>
|
|
|
|
#include <cassert>
|
|
#include <cstddef>
|
|
#include <memory>
|
|
#include <optional>
|
|
#include <vector>
|
|
|
|
static void SizeComputerBlockBench(benchmark::Bench& bench) {
|
|
CBlock block;
|
|
DataStream(benchmark::data::block413567) >> TX_WITH_WITNESS(block);
|
|
|
|
bench.unit("block").run([&] {
|
|
SizeComputer size_computer;
|
|
size_computer << TX_WITH_WITNESS(block);
|
|
assert(size_computer.size() == benchmark::data::block413567.size());
|
|
});
|
|
}
|
|
|
|
static void SerializeBlockBench(benchmark::Bench& bench) {
|
|
CBlock block;
|
|
DataStream(benchmark::data::block413567) >> TX_WITH_WITNESS(block);
|
|
|
|
// Create output stream and verify first serialization matches input
|
|
bench.unit("block").run([&] {
|
|
DataStream output_stream(benchmark::data::block413567.size());
|
|
output_stream << TX_WITH_WITNESS(block);
|
|
assert(output_stream.size() == benchmark::data::block413567.size());
|
|
});
|
|
}
|
|
|
|
// These are the two major time-sinks which happen after we have fully received
|
|
// a block off the wire, but before we can relay the block on to peers using
|
|
// compact block relay.
|
|
|
|
static void DeserializeBlockBench(benchmark::Bench& bench)
|
|
{
|
|
DataStream stream(benchmark::data::block413567);
|
|
std::byte a{0};
|
|
stream.write(std::span{&a, 1}); // Prevent compaction
|
|
|
|
bench.unit("block").run([&] {
|
|
CBlock block;
|
|
stream >> TX_WITH_WITNESS(block);
|
|
bool rewound = stream.Rewind(benchmark::data::block413567.size());
|
|
assert(rewound);
|
|
});
|
|
}
|
|
|
|
static void DeserializeAndCheckBlock(benchmark::Bench& bench)
|
|
{
|
|
DataStream stream(benchmark::data::block413567);
|
|
std::byte a{0};
|
|
stream.write(std::span{&a, 1}); // Prevent compaction
|
|
|
|
ArgsManager bench_args;
|
|
const auto chainParams = CreateChainParams(bench_args, ChainType::MAIN);
|
|
|
|
bench.unit("block").run([&] {
|
|
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
|
|
stream >> TX_WITH_WITNESS(block);
|
|
bool rewound = stream.Rewind(benchmark::data::block413567.size());
|
|
assert(rewound);
|
|
|
|
BlockValidationState validationState;
|
|
bool checked = CheckBlock(block, validationState, chainParams->GetConsensus());
|
|
assert(checked);
|
|
});
|
|
}
|
|
|
|
BENCHMARK(SizeComputerBlockBench, benchmark::PriorityLevel::HIGH);
|
|
BENCHMARK(SerializeBlockBench, benchmark::PriorityLevel::HIGH);
|
|
BENCHMARK(DeserializeBlockBench, benchmark::PriorityLevel::HIGH);
|
|
BENCHMARK(DeserializeAndCheckBlock, benchmark::PriorityLevel::HIGH);
|