Merge #9226: Remove fNetworkNode and pnodeLocalHost.
[bitcoinplatinum.git] / src / bench / checkblock.cpp
blob4a564d3fc82549fdbe9fd280e568b7dfde0ed798
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.
5 #include "bench.h"
7 #include "chainparams.h"
8 #include "main.h"
9 #include "consensus/validation.h"
11 namespace block_bench {
12 #include "bench/data/block413567.raw.h"
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.
19 static void DeserializeBlockTest(benchmark::State& state)
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
27 while (state.KeepRunning()) {
28 CBlock block;
29 stream >> block;
30 assert(stream.Rewind(sizeof(block_bench::block413567)));
34 static void DeserializeAndCheckBlockTest(benchmark::State& state)
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
42 Consensus::Params params = Params(CBaseChainParams::MAIN).GetConsensus();
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)));
49 CValidationState validationState;
50 assert(CheckBlock(block, validationState, params));
54 BENCHMARK(DeserializeBlockTest);
55 BENCHMARK(DeserializeAndCheckBlockTest);