Changeset View
Changeset View
Standalone View
Standalone View
src/bench/checkblock.cpp
Show All 23 Lines | CDataStream stream((const char *)block_bench::block413567, | ||||
block_bench::block413567)], | block_bench::block413567)], | ||||
SER_NETWORK, PROTOCOL_VERSION); | SER_NETWORK, PROTOCOL_VERSION); | ||||
char a = '\0'; | char a = '\0'; | ||||
stream.write(&a, 1); // Prevent compaction | stream.write(&a, 1); // Prevent compaction | ||||
while (state.KeepRunning()) { | while (state.KeepRunning()) { | ||||
CBlock block; | CBlock block; | ||||
stream >> block; | stream >> block; | ||||
assert(stream.Rewind(sizeof(block_bench::block413567))); | bool rewound = stream.Rewind(sizeof(block_bench::block413567)); | ||||
assert(rewound); | |||||
} | } | ||||
} | } | ||||
static void DeserializeAndCheckBlockTest(benchmark::State &state) { | static void DeserializeAndCheckBlockTest(benchmark::State &state) { | ||||
CDataStream stream((const char *)block_bench::block413567, | CDataStream stream((const char *)block_bench::block413567, | ||||
(const char *)&block_bench::block413567[sizeof( | (const char *)&block_bench::block413567[sizeof( | ||||
block_bench::block413567)], | block_bench::block413567)], | ||||
SER_NETWORK, PROTOCOL_VERSION); | SER_NETWORK, 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()) { | while (state.KeepRunning()) { | ||||
// 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; | ||||
assert(stream.Rewind(sizeof(block_bench::block413567))); | bool rewound = stream.Rewind(sizeof(block_bench::block413567)); | ||||
assert(rewound); | |||||
CValidationState validationState; | CValidationState validationState; | ||||
bool ret = CheckBlock(block, validationState, params, options); | bool checked = CheckBlock(block, validationState, params, options); | ||||
assert(ret); | assert(checked); | ||||
} | } | ||||
} | } | ||||
BENCHMARK(DeserializeBlockTest, 130); | BENCHMARK(DeserializeBlockTest, 130); | ||||
BENCHMARK(DeserializeAndCheckBlockTest, 160); | BENCHMARK(DeserializeAndCheckBlockTest, 160); |