mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-03-02 09:46:14 +00:00
-BEGIN VERIFY SCRIPT- sed --in-place --regexp-extended 's/BENCHMARK\(([^,]+), benchmark::PriorityLevel::(HIGH|LOW)\)/BENCHMARK(\1)/g' $( git grep -l PriorityLevel ) sed --in-place 's/#define BENCHMARK(n, priority_level)/#define BENCHMARK(n)/g' ./src/bench/bench.h -END VERIFY SCRIPT-
65 lines
2.0 KiB
C++
65 lines
2.0 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 <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>
|
|
|
|
// 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)
|
|
{
|
|
DataStream stream(benchmark::data::block413567);
|
|
std::byte a{0};
|
|
stream.write({&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 DeserializeAndCheckBlockTest(benchmark::Bench& bench)
|
|
{
|
|
DataStream stream(benchmark::data::block413567);
|
|
std::byte a{0};
|
|
stream.write({&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(DeserializeBlockTest);
|
|
BENCHMARK(DeserializeAndCheckBlockTest);
|