2016-06-01 10:39:56 +02:00
|
|
|
// Copyright (c) 2016 The Bitcoin Core developers
|
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
|
|
|
#include "bench.h"
|
|
|
|
|
|
|
|
#include "chainparams.h"
|
2016-12-02 01:06:41 +01:00
|
|
|
#include "validation.h"
|
2016-12-02 00:45:50 +01:00
|
|
|
#include "streams.h"
|
2016-06-01 10:39:56 +02:00
|
|
|
#include "consensus/validation.h"
|
|
|
|
|
|
|
|
namespace block_bench {
|
|
|
|
#include "bench/data/block413567.raw.h"
|
|
|
|
}
|
|
|
|
|
|
|
|
// These are the two major time-sinks which happen after we have fully received
|
|
|
|
// a block off the wire, but before we can relay the block on to peers using
|
|
|
|
// compact block relay.
|
|
|
|
|
|
|
|
static void DeserializeBlockTest(benchmark::State& state)
|
|
|
|
{
|
|
|
|
CDataStream stream((const char*)block_bench::block413567,
|
|
|
|
(const char*)&block_bench::block413567[sizeof(block_bench::block413567)],
|
|
|
|
SER_NETWORK, PROTOCOL_VERSION);
|
2017-03-08 16:40:12 +01:00
|
|
|
char a = '\0';
|
2016-06-01 10:39:56 +02:00
|
|
|
stream.write(&a, 1); // Prevent compaction
|
|
|
|
|
|
|
|
while (state.KeepRunning()) {
|
|
|
|
CBlock block;
|
|
|
|
stream >> block;
|
|
|
|
assert(stream.Rewind(sizeof(block_bench::block413567)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DeserializeAndCheckBlockTest(benchmark::State& state)
|
|
|
|
{
|
|
|
|
CDataStream stream((const char*)block_bench::block413567,
|
|
|
|
(const char*)&block_bench::block413567[sizeof(block_bench::block413567)],
|
|
|
|
SER_NETWORK, PROTOCOL_VERSION);
|
2017-03-08 16:40:12 +01:00
|
|
|
char a = '\0';
|
2016-06-01 10:39:56 +02:00
|
|
|
stream.write(&a, 1); // Prevent compaction
|
|
|
|
|
|
|
|
Consensus::Params params = Params(CBaseChainParams::MAIN).GetConsensus();
|
|
|
|
|
|
|
|
while (state.KeepRunning()) {
|
|
|
|
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
|
|
|
|
stream >> block;
|
|
|
|
assert(stream.Rewind(sizeof(block_bench::block413567)));
|
|
|
|
|
2016-11-10 21:38:07 +01:00
|
|
|
CValidationState validationState;
|
|
|
|
assert(CheckBlock(block, validationState, params));
|
2016-06-01 10:39:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
BENCHMARK(DeserializeBlockTest);
|
|
|
|
BENCHMARK(DeserializeAndCheckBlockTest);
|