Changeset View
Changeset View
Standalone View
Standalone View
src/bench/rpc_blockchain.cpp
// Copyright (c) 2016-2019 The Bitcoin Core developers | // Copyright (c) 2016-2019 The Bitcoin Core developers | ||||
// Distributed under the MIT software license, see the accompanying | // Distributed under the MIT software license, see the accompanying | ||||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | // file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||||
#include <bench/bench.h> | #include <bench/bench.h> | ||||
#include <bench/data.h> | #include <bench/data.h> | ||||
#include <rpc/blockchain.h> | #include <rpc/blockchain.h> | ||||
#include <streams.h> | #include <streams.h> | ||||
#include <validation.h> | #include <validation.h> | ||||
#include <univalue.h> | #include <univalue.h> | ||||
static void BlockToJsonVerbose(benchmark::State &state) { | static void BlockToJsonVerbose(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'; | ||||
// Prevent compaction | // Prevent compaction | ||||
stream.write(&a, 1); | stream.write(&a, 1); | ||||
CBlock block; | CBlock block; | ||||
stream >> block; | stream >> block; | ||||
CBlockIndex blockindex; | CBlockIndex blockindex; | ||||
const auto blockHash = block.GetHash(); | const auto blockHash = block.GetHash(); | ||||
blockindex.phashBlock = &blockHash; | blockindex.phashBlock = &blockHash; | ||||
blockindex.nBits = 403014710; | blockindex.nBits = 403014710; | ||||
while (state.KeepRunning()) { | bench.run([&] { | ||||
(void)blockToJSON(block, &blockindex, &blockindex, /*verbose*/ true); | (void)blockToJSON(block, &blockindex, &blockindex, /*verbose*/ true); | ||||
} | }); | ||||
} | } | ||||
BENCHMARK(BlockToJsonVerbose, 10); | BENCHMARK(BlockToJsonVerbose); |