|
| 1 | +// Copyright (c) 2016 The Bitcoin Core developers |
| 2 | +// Distributed under the MIT software license, see the accompanying |
| 3 | +// file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 4 | + |
| 5 | +#include "bench.h" |
| 6 | + |
| 7 | +#include "chainparams.h" |
| 8 | +#include "main.h" |
| 9 | +#include "consensus/validation.h" |
| 10 | + |
| 11 | +namespace block_bench { |
| 12 | +#include "bench/data/block413567.raw.h" |
| 13 | +} |
| 14 | + |
| 15 | +// These are the two major time-sinks which happen after we have fully received |
| 16 | +// a block off the wire, but before we can relay the block on to peers using |
| 17 | +// compact block relay. |
| 18 | + |
| 19 | +static void DeserializeBlockTest(benchmark::State& state) |
| 20 | +{ |
| 21 | + CDataStream stream((const char*)block_bench::block413567, |
| 22 | + (const char*)&block_bench::block413567[sizeof(block_bench::block413567)], |
| 23 | + SER_NETWORK, PROTOCOL_VERSION); |
| 24 | + char a; |
| 25 | + stream.write(&a, 1); // Prevent compaction |
| 26 | + |
| 27 | + while (state.KeepRunning()) { |
| 28 | + CBlock block; |
| 29 | + stream >> block; |
| 30 | + assert(stream.Rewind(sizeof(block_bench::block413567))); |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +static void DeserializeAndCheckBlockTest(benchmark::State& state) |
| 35 | +{ |
| 36 | + CDataStream stream((const char*)block_bench::block413567, |
| 37 | + (const char*)&block_bench::block413567[sizeof(block_bench::block413567)], |
| 38 | + SER_NETWORK, PROTOCOL_VERSION); |
| 39 | + char a; |
| 40 | + stream.write(&a, 1); // Prevent compaction |
| 41 | + |
| 42 | + Consensus::Params params = Params(CBaseChainParams::MAIN).GetConsensus(); |
| 43 | + |
| 44 | + while (state.KeepRunning()) { |
| 45 | + CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here |
| 46 | + stream >> block; |
| 47 | + assert(stream.Rewind(sizeof(block_bench::block413567))); |
| 48 | + |
| 49 | + CValidationState state; |
| 50 | + assert(CheckBlock(block, state, params)); |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +BENCHMARK(DeserializeBlockTest); |
| 55 | +BENCHMARK(DeserializeAndCheckBlockTest); |
0 commit comments