2018-07-27 00:36:45 +02:00
|
|
|
// Copyright (c) 2016-2018 The Bitcoin Core developers
|
2016-06-01 10:39:56 +02:00
|
|
|
// Distributed under the MIT software license, see the accompanying
|
|
|
|
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <bench/bench.h>
|
2016-06-01 10:39:56 +02:00
|
|
|
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <chainparams.h>
|
|
|
|
#include <validation.h>
|
|
|
|
#include <streams.h>
|
|
|
|
#include <consensus/validation.h>
|
2016-06-01 10:39:56 +02:00
|
|
|
|
|
|
|
namespace block_bench {
|
2017-11-10 01:57:53 +01:00
|
|
|
#include <bench/data/block413567.raw.h>
|
2017-05-31 22:21:25 +02:00
|
|
|
} // namespace block_bench
|
2016-06-01 10:39:56 +02:00
|
|
|
|
|
|
|
// 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,
|
2018-10-05 09:43:09 +02:00
|
|
|
(const char*)block_bench::block413567 + sizeof(block_bench::block413567),
|
2016-06-01 10:39:56 +02:00
|
|
|
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;
|
2018-06-26 17:19:31 +02:00
|
|
|
bool rewound = stream.Rewind(sizeof(block_bench::block413567));
|
|
|
|
assert(rewound);
|
2016-06-01 10:39:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void DeserializeAndCheckBlockTest(benchmark::State& state)
|
|
|
|
{
|
|
|
|
CDataStream stream((const char*)block_bench::block413567,
|
2018-10-05 09:43:09 +02:00
|
|
|
(const char*)block_bench::block413567 + sizeof(block_bench::block413567),
|
2016-06-01 10:39:56 +02:00
|
|
|
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
|
|
|
|
|
2015-11-28 15:04:35 +01:00
|
|
|
const auto chainParams = CreateChainParams(CBaseChainParams::MAIN);
|
2016-06-01 10:39:56 +02:00
|
|
|
|
|
|
|
while (state.KeepRunning()) {
|
|
|
|
CBlock block; // Note that CBlock caches its checked state, so we need to recreate it here
|
|
|
|
stream >> block;
|
2018-06-26 17:19:31 +02:00
|
|
|
bool rewound = stream.Rewind(sizeof(block_bench::block413567));
|
|
|
|
assert(rewound);
|
2016-06-01 10:39:56 +02:00
|
|
|
|
2016-11-10 21:38:07 +01:00
|
|
|
CValidationState validationState;
|
2018-06-26 17:19:31 +02:00
|
|
|
bool checked = CheckBlock(block, validationState, chainParams->GetConsensus());
|
|
|
|
assert(checked);
|
2016-06-01 10:39:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-17 16:48:02 +02:00
|
|
|
BENCHMARK(DeserializeBlockTest, 130);
|
|
|
|
BENCHMARK(DeserializeAndCheckBlockTest, 160);
|