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.
7 #include "chainparams.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
);
25 stream
.write(&a
, 1); // Prevent compaction
27 while (state
.KeepRunning()) {
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
);
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
47 assert(stream
.Rewind(sizeof(block_bench::block413567
)));
49 CValidationState validationState
;
50 assert(CheckBlock(block
, validationState
, params
));
54 BENCHMARK(DeserializeBlockTest
);
55 BENCHMARK(DeserializeAndCheckBlockTest
);