Changeset View
Changeset View
Standalone View
Standalone View
src/bench/checkblock.cpp
Show All 9 Lines | |||||
#include <consensus/validation.h> | #include <consensus/validation.h> | ||||
#include <streams.h> | #include <streams.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
// These are the two major time-sinks which happen after we have fully received | // 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 | // a block off the wire, but before we can relay the block on to peers using | ||||
// compact block relay. | // compact block relay. | ||||
static void DeserializeBlockTest(benchmark::State &state) { | static void DeserializeBlockTest(benchmark::Bench &bench) { | ||||
CDataStream stream(benchmark::data::block413567, SER_NETWORK, | CDataStream stream(benchmark::data::block413567, SER_NETWORK, | ||||
PROTOCOL_VERSION); | PROTOCOL_VERSION); | ||||
char a = '\0'; | char a = '\0'; | ||||
stream.write(&a, 1); // Prevent compaction | stream.write(&a, 1); // Prevent compaction | ||||
while (state.KeepRunning()) { | bench.unit("block").run([&] { | ||||
CBlock block; | CBlock block; | ||||
stream >> block; | stream >> block; | ||||
bool rewound = stream.Rewind(benchmark::data::block413567.size()); | bool rewound = stream.Rewind(benchmark::data::block413567.size()); | ||||
assert(rewound); | assert(rewound); | ||||
} | }); | ||||
} | } | ||||
static void DeserializeAndCheckBlockTest(benchmark::State &state) { | static void DeserializeAndCheckBlockTest(benchmark::Bench &bench) { | ||||
CDataStream stream(benchmark::data::block413567, SER_NETWORK, | CDataStream stream(benchmark::data::block413567, SER_NETWORK, | ||||
PROTOCOL_VERSION); | PROTOCOL_VERSION); | ||||
char a = '\0'; | char a = '\0'; | ||||
stream.write(&a, 1); // Prevent compaction | stream.write(&a, 1); // Prevent compaction | ||||
const Config &config = GetConfig(); | const Config &config = GetConfig(); | ||||
const Consensus::Params params = config.GetChainParams().GetConsensus(); | const Consensus::Params params = config.GetChainParams().GetConsensus(); | ||||
BlockValidationOptions options(config); | BlockValidationOptions options(config); | ||||
while (state.KeepRunning()) { | bench.unit("block").run([&] { | ||||
// Note that CBlock caches its checked state, so we need to recreate it | // Note that CBlock caches its checked state, so we need to recreate it | ||||
// here. | // here. | ||||
CBlock block; | CBlock block; | ||||
stream >> block; | stream >> block; | ||||
bool rewound = stream.Rewind(benchmark::data::block413567.size()); | bool rewound = stream.Rewind(benchmark::data::block413567.size()); | ||||
assert(rewound); | assert(rewound); | ||||
BlockValidationState validationState; | BlockValidationState validationState; | ||||
bool checked = CheckBlock(block, validationState, params, options); | bool checked = CheckBlock(block, validationState, params, options); | ||||
assert(checked); | assert(checked); | ||||
} | }); | ||||
} | } | ||||
BENCHMARK(DeserializeBlockTest, 130); | BENCHMARK(DeserializeBlockTest); | ||||
BENCHMARK(DeserializeAndCheckBlockTest, 160); | BENCHMARK(DeserializeAndCheckBlockTest); |