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 <coins.h>7#include <consensus/amount.h>8#include <consensus/validation.h>9#include <key.h>10#include <policy/policy.h>11#include <primitives/transaction.h>12#include <script/script.h>13#include <script/signingprovider.h>14#include <test/util/transaction_utils.h>15#include <util/check.h>17#include <array>18#include <span>19#include <vector>21// Microbenchmark for simple accesses to a CCoinsViewCache database. Note from22// laanwj, "replicating the actual usage patterns of the client is hard though,23// many times micro-benchmarks of the database showed completely different24// characteristics than e.g. reindex timings. But that's not a requirement of25// every benchmark."26// (https://github.com/bitcoin/bitcoin/issues/7883#issuecomment-224807484)27static void CCoinsCaching(benchmark::Bench& bench)28{29ECC_Context ecc_context{};31FillableSigningProvider keystore;32CCoinsViewCache coins{&CoinsViewEmpty::Get()};33std::vector<CMutableTransaction> dummyTransactions =34SetupDummyInputs(keystore, coins, {11 * COIN, 50 * COIN, 21 * COIN, 22 * COIN});36CMutableTransaction t1;37t1.vin.resize(3);38t1.vin[0].prevout.hash = dummyTransactions[0].GetHash();39t1.vin[0].prevout.n = 1;40t1.vin[0].scriptSig << std::vector<unsigned char>(65, 0);41t1.vin[1].prevout.hash = dummyTransactions[1].GetHash();42t1.vin[1].prevout.n = 0;43t1.vin[1].scriptSig << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4);44t1.vin[2].prevout.hash = dummyTransactions[1].GetHash();45t1.vin[2].prevout.n = 1;46t1.vin[2].scriptSig << std::vector<unsigned char>(65, 0) << std::vector<unsigned char>(33, 4);47t1.vout.resize(2);48t1.vout[0].nValue = 90 * COIN;49t1.vout[0].scriptPubKey << OP_1;51// Benchmark.52const CTransaction tx_1(t1);53bench.run([&] {54assert(ValidateInputsStandardness(tx_1, coins).IsValid());55});56}58BENCHMARK(CCoinsCaching);
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.