Changeset View
Changeset View
Standalone View
Standalone View
src/bench/checkblock.cpp
// Copyright (c) 2016 The Bitcoin Core developers | // Copyright (c) 2016 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include "bench.h" | #include "bench.h" | ||||
#include "chainparams.h" | |||||
#include "config.h" | #include "config.h" | ||||
#include "consensus/validation.h" | #include "consensus/validation.h" | ||||
#include "streams.h" | #include "streams.h" | ||||
#include "validation.h" | #include "validation.h" | ||||
namespace block_bench { | namespace block_bench { | ||||
#include "bench/data/block413567.raw.h" | #include "bench/data/block413567.raw.h" | ||||
} | } | ||||
Show All 21 Lines | static void DeserializeAndCheckBlockTest(benchmark::State &state) { | ||||
CDataStream stream((const char *)block_bench::block413567, | CDataStream stream((const char *)block_bench::block413567, | ||||
(const char *)&block_bench::block413567[sizeof( | (const char *)&block_bench::block413567[sizeof( | ||||
block_bench::block413567)], | block_bench::block413567)], | ||||
SER_NETWORK, PROTOCOL_VERSION); | SER_NETWORK, PROTOCOL_VERSION); | ||||
char a; | char a; | ||||
stream.write(&a, 1); // Prevent compaction | stream.write(&a, 1); // Prevent compaction | ||||
const Config &config = GetConfig(); | const Config &config = GetConfig(); | ||||
Consensus::Params params = Params(CBaseChainParams::MAIN).GetConsensus(); | |||||
while (state.KeepRunning()) { | while (state.KeepRunning()) { | ||||
// Note that CBlock caches its checked state, so we need to recreate it | // Note that CBlock caches its checked state, so we need to recreate it | ||||
// here. | // here. | ||||
CBlock block; | CBlock block; | ||||
stream >> block; | stream >> block; | ||||
assert(stream.Rewind(sizeof(block_bench::block413567))); | assert(stream.Rewind(sizeof(block_bench::block413567))); | ||||
CValidationState validationState; | CValidationState validationState; | ||||
assert(CheckBlock(config, block, validationState, params)); | assert(CheckBlock(config, block, validationState)); | ||||
} | } | ||||
} | } | ||||
BENCHMARK(DeserializeBlockTest); | BENCHMARK(DeserializeBlockTest); | ||||
BENCHMARK(DeserializeAndCheckBlockTest); | BENCHMARK(DeserializeAndCheckBlockTest); |