mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-13 22:41:25 +02:00
55 lines
1.6 KiB
C++
55 lines
1.6 KiB
C++
// Copyright (c) 2016-present 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 <consensus/validation.h>
|
|
#include <kernel/chainparams.h>
|
|
#include <primitives/block.h>
|
|
#include <primitives/transaction.h>
|
|
#include <serialize.h>
|
|
#include <streams.h>
|
|
#include <util/check.h>
|
|
#include <validation.h>
|
|
|
|
#include <memory>
|
|
#include <span>
|
|
#include <vector>
|
|
|
|
// 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 DeserializeBlockTest(benchmark::Bench& bench)
|
|
{
|
|
const auto block_data{benchmark::data::block413567};
|
|
bench.unit("block").run([&] {
|
|
CBlock block;
|
|
SpanReader{block_data} >> TX_WITH_WITNESS(block);
|
|
assert(block.vtx.size() == 1557);
|
|
});
|
|
}
|
|
|
|
static void CheckBlockTest(benchmark::Bench& bench)
|
|
{
|
|
const auto& chain_params{CChainParams::Main()};
|
|
const auto block_data{benchmark::data::block413567};
|
|
|
|
CBlock block;
|
|
bench.unit("block")
|
|
.setup([&] {
|
|
block = CBlock{};
|
|
SpanReader{block_data} >> TX_WITH_WITNESS(block);
|
|
assert(block.vtx.size() == 1557);
|
|
})
|
|
.run([&] {
|
|
BlockValidationState validationState;
|
|
const bool checked{CheckBlock(block, validationState, chain_params->GetConsensus())};
|
|
assert(checked);
|
|
});
|
|
}
|
|
|
|
BENCHMARK(DeserializeBlockTest);
|
|
BENCHMARK(CheckBlockTest);
|