Inside Bitcoin
Opening the selected file…
Inside Bitcoin
Opening the selected file…
The code behind the network, with room to understand it.
Release published 2026-10-28 · Snapshot fetched 2026-11-01. Latest stable release at fetch time; development branches and Git history are excluded. Only the selected code window and visible folders load here.
1// Copyright (c) 2016-present The Bitcoin Core developers2// Distributed under the MIT software license, see the accompanying3// file COPYING or http://www.opensource.org/licenses/mit-license.php.5#include <bench/bench.h>6#include <bench/data/block413567.raw.h>7#include <chain.h>8#include <consensus/params.h>9#include <core_io.h>10#include <kernel/chainparams.h>11#include <primitives/block.h>12#include <primitives/transaction.h>13#include <rpc/blockchain.h>14#include <serialize.h>15#include <streams.h>16#include <test/util/setup_common.h>17#include <uint256.h>18#include <univalue.h>19#include <validation.h>21#include <memory>22#include <span>23#include <string>25namespace {27struct TestBlockAndIndex {28const std::unique_ptr<const TestingSetup> testing_setup{MakeNoLogFileContext<const TestingSetup>(ChainType::MAIN)};29CBlock block{};30uint256 blockHash{};31CBlockIndex blockindex{};33TestBlockAndIndex()34{35SpanReader stream{benchmark::data::block413567};36stream >> TX_WITH_WITNESS(block);38blockHash = block.GetHash();39blockindex.phashBlock = &blockHash;40blockindex.nBits = 403014710;41}42};44} // namespace46static void BlockToJson(benchmark::Bench& bench, TxVerbosity verbosity)47{48TestBlockAndIndex data;49const uint256 pow_limit{data.testing_setup->m_node.chainman->GetParams().GetConsensus().powLimit};50bench.run([&] {51auto univalue = blockToJSON(data.testing_setup->m_node.chainman->m_blockman, data.block, data.blockindex, data.blockindex, verbosity, pow_limit);52ankerl::nanobench::doNotOptimizeAway(univalue);53});54}56static void BlockToJsonVerbosity1(benchmark::Bench& bench)57{58BlockToJson(bench, TxVerbosity::SHOW_TXID);59}61static void BlockToJsonVerbosity2(benchmark::Bench& bench)62{63BlockToJson(bench, TxVerbosity::SHOW_DETAILS);64}66static void BlockToJsonVerbosity3(benchmark::Bench& bench)67{68BlockToJson(bench, TxVerbosity::SHOW_DETAILS_AND_PREVOUT);69}71BENCHMARK(BlockToJsonVerbosity1);72BENCHMARK(BlockToJsonVerbosity2);73BENCHMARK(BlockToJsonVerbosity3);75static void BlockToJsonVerboseWrite(benchmark::Bench& bench)76{77TestBlockAndIndex data;78const uint256 pow_limit{data.testing_setup->m_node.chainman->GetParams().GetConsensus().powLimit};79auto univalue = blockToJSON(data.testing_setup->m_node.chainman->m_blockman, data.block, data.blockindex, data.blockindex, TxVerbosity::SHOW_DETAILS_AND_PREVOUT, pow_limit);80bench.run([&] {81auto str = univalue.write();82ankerl::nanobench::doNotOptimizeAway(str);83});84}86BENCHMARK(BlockToJsonVerboseWrite);
Independent explanations by MyBitcoinExplorer. Not affiliated with or endorsed by Bitcoin Core. Guides are educational and do not replace the source or its tests.
Bitcoin Core source © its contributors, distributed under the MIT license. Original notices and bundled third-party licenses are retained in the source tree.