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) 2015-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 <checkqueue.h>7#include <common/system.h>8#include <key.h>9#include <prevector.h>10#include <random.h>11#include <script/script.h>13#include <cstddef>14#include <cstdint>15#include <optional>16#include <utility>17#include <vector>19static const size_t BATCHES = 101;20static const size_t BATCH_SIZE = 30;21static const unsigned int QUEUE_BATCH_SIZE = 128;23// This Benchmark tests the CheckQueue with a slightly realistic workload,24// where checks all contain a prevector that is indirect 50% of the time25// and there is a little bit of work done between calls to Add.26static void CCheckQueueSpeedPrevectorJob(benchmark::Bench& bench)27{28// We shouldn't ever be running with the checkqueue on a single core machine.29if (GetNumCores() <= 1) return;31ECC_Context ecc_context{};33struct PrevectorJob {34prevector<CScriptBase::STATIC_SIZE, uint8_t> p;35explicit PrevectorJob(FastRandomContext& insecure_rand){36p.resize(insecure_rand.randrange(CScriptBase::STATIC_SIZE * 2));37}38std::optional<int> operator()()39{40return std::nullopt;41}42};44// The main thread should be counted to prevent thread oversubscription, and45// to decrease the variance of benchmark results.46int worker_threads_num{GetNumCores() - 1};47CCheckQueue<PrevectorJob> queue{QUEUE_BATCH_SIZE, worker_threads_num};49// create all the data once, then submit copies in the benchmark.50FastRandomContext insecure_rand(true);51std::vector<std::vector<PrevectorJob>> vBatches(BATCHES);52for (auto& vChecks : vBatches) {53vChecks.reserve(BATCH_SIZE);54for (size_t x = 0; x < BATCH_SIZE; ++x)55vChecks.emplace_back(insecure_rand);56}58bench.minEpochIterations(10).batch(BATCH_SIZE * BATCHES).unit("job").run([&] {59// Make insecure_rand here so that each iteration is identical.60CCheckQueueControl<PrevectorJob> control(queue);61for (auto vChecks : vBatches) {62control.Add(std::move(vChecks));63}64// control waits for completion by RAII, but65// it is done explicitly here for clarity66control.Complete();67});68}69BENCHMARK(CCheckQueueSpeedPrevectorJob);
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.