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#ifndef BITCOIN_BENCH_BENCH_H6#define BITCOIN_BENCH_BENCH_H8#include <bench/nanobench.h> // IWYU pragma: export9#include <util/fs.h>10#include <util/macros.h>11#include <util/time.h>13#include <functional>14#include <map>15#include <string>16#include <string_view>17#include <vector>19/*20* Usage:22static void NameOfYourBenchmarkFunction(benchmark::Bench& bench)23{24...do any setup needed...26bench.run([&] {27...do stuff you want to time; refer to src/bench/nanobench.h28for more information and the options that can be passed here...29});31...do any cleanup needed...32}34BENCHMARK(NameOfYourBenchmarkFunction);36*/38namespace benchmark {40using ankerl::nanobench::Bench;42using BenchFunction = std::function<void(Bench&)>;44struct Args {45bool is_list_only;46bool sanity_check;47std::chrono::milliseconds min_time;48std::vector<double> asymptote;49fs::path output_csv;50fs::path output_json;51std::string regex_filter;52std::vector<std::string> setup_args;53};55class BenchRunner56{57// maps from "name" -> function58using BenchmarkMap = std::map<std::string, BenchFunction>;59static BenchmarkMap& benchmarks();61public:62BenchRunner(std::string_view name, BenchFunction func);64static void RunAll(const Args& args);65};66} // namespace benchmark68// BENCHMARK(foo); expands to: benchmark::BenchRunner bench_runner_foo{"foo", foo};69#define BENCHMARK(n) \70benchmark::BenchRunner PASTE2(bench_runner_, n) { STRINGIZE(n), n }72#endif // BITCOIN_BENCH_BENCH_H
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.