Merge #12079: Improve prioritisetransaction test coverage
[bitcoinplatinum.git] / src / bench / checkblock.cpp
blobfac7e079a73107c13ef64c9660979443acb24751
1 // Copyright (c) 2016-2017 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/bench.h>
7 #include <chainparams.h>
8 #include <validation.h>
9 #include <streams.h>
10 #include <consensus/validation.h>
12 namespace block_bench {
13 #include <bench/data/block413567.raw.h>
14 } // namespace block_bench
16 // These are the two major time-sinks which happen after we have fully received
17 // a block off the wire, but before we can relay the block on to peers using
18 // compact block relay.
20 static void DeserializeBlockTest(benchmark::State& state)
22 CDataStream stream((const char*)block_bench::block413567,
23 (const char*)&block_bench::block413567[sizeof(block_bench::block413567)],
24 SER_NETWORK, PROTOCOL_VERSION);
25 char a = '\0';
26 stream.write(&a, 1); // Prevent compaction
28 while (state.KeepRunning()) {
29 CBlock block;
30 stream >> block;
31 assert(stream.Rewind(sizeof(block_bench::block413567)));
35 static void DeserializeAndCheckBlockTest(benchmark::State& state)
37 CDataStream stream((const char*)block_bench::block413567,
38 (const char*)&block_bench::block413567[sizeof(block_bench::block413567)],
39 SER_NETWORK, PROTOCOL_VERSION);
40 char a = '\0';
41 stream.write(&a, 1); // Prevent compaction
43 const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
45 while (state.KeepRunning()) {
46 CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
47 stream >> block;
48 assert(stream.Rewind(sizeof(block_bench::block413567)));
50 CValidationState validationState;
51 assert(CheckBlock(block, validationState, chainParams->GetConsensus()));
55 BENCHMARK(DeserializeBlockTest, 130);
56 BENCHMARK(DeserializeAndCheckBlockTest, 160);