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.
3251}3253std::string const& Bench::unit() const noexcept {3254return mConfig.mUnit;3255}3257Bench& Bench::timeUnit(std::chrono::duration<double> const& tu, std::string const& tuName) {3258mConfig.mTimeUnit = tu;3259mConfig.mTimeUnitName = tuName;3260return *this;3261}3263std::string const& Bench::timeUnitName() const noexcept {3264return mConfig.mTimeUnitName;3265}3267std::chrono::duration<double> const& Bench::timeUnit() const noexcept {3268return mConfig.mTimeUnit;3269}3271// If benchmarkTitle differs from currently set title, the stored results will be cleared.3272Bench& Bench::title(const char* benchmarkTitle) {3273if (benchmarkTitle != mConfig.mBenchmarkTitle) {3274mResults.clear();3275}3276mConfig.mBenchmarkTitle = benchmarkTitle;3277return *this;3278}3279Bench& Bench::title(std::string const& benchmarkTitle) {3280if (benchmarkTitle != mConfig.mBenchmarkTitle) {3281mResults.clear();3282}3283mConfig.mBenchmarkTitle = benchmarkTitle;3284return *this;3285}3287std::string const& Bench::title() const noexcept {3288return mConfig.mBenchmarkTitle;3289}3291Bench& Bench::name(const char* benchmarkName) {3292mConfig.mBenchmarkName = benchmarkName;3293return *this;3294}3296Bench& Bench::name(std::string const& benchmarkName) {3297mConfig.mBenchmarkName = benchmarkName;3298return *this;3299}3301std::string const& Bench::name() const noexcept {3302return mConfig.mBenchmarkName;3303}3305Bench& Bench::context(char const* variableName, char const* variableValue) {3306mConfig.mContext[variableName] = variableValue;3307return *this;3308}3310Bench& Bench::context(std::string const& variableName, std::string const& variableValue) {3311mConfig.mContext[variableName] = variableValue;3312return *this;3313}3315Bench& Bench::clearContext() {3316mConfig.mContext.clear();3317return *this;3318}3320// Number of epochs to evaluate. The reported result will be the median of evaluation of each epoch.3321Bench& Bench::epochs(size_t numEpochs) noexcept {3322mConfig.mNumEpochs = numEpochs;3323return *this;3324}3325size_t Bench::epochs() const noexcept {3326return mConfig.mNumEpochs;3327}3329// Desired evaluation time is a multiple of clock resolution. Default is to be 1000 times above this measurement precision.3330Bench& Bench::clockResolutionMultiple(size_t multiple) noexcept {3331mConfig.mClockResolutionMultiple = multiple;3332return *this;3333}3334size_t Bench::clockResolutionMultiple() const noexcept {3335return mConfig.mClockResolutionMultiple;3336}3338// Sets the maximum time each epoch should take. Default is 100ms.3339Bench& Bench::maxEpochTime(std::chrono::nanoseconds t) noexcept {3340mConfig.mMaxEpochTime = t;3341return *this;3342}3343std::chrono::nanoseconds Bench::maxEpochTime() const noexcept {3344return mConfig.mMaxEpochTime;3345}3347// Sets the maximum time each epoch should take. Default is 100ms.3348Bench& Bench::minEpochTime(std::chrono::nanoseconds t) noexcept {3349mConfig.mMinEpochTime = t;3350return *this;3351}3352std::chrono::nanoseconds Bench::minEpochTime() const noexcept {3353return mConfig.mMinEpochTime;3354}3356Bench& Bench::minEpochIterations(uint64_t numIters) noexcept {3357mConfig.mMinEpochIterations = (numIters == 0) ? 1 : numIters;3358return *this;3359}3360uint64_t Bench::minEpochIterations() const noexcept {3361return mConfig.mMinEpochIterations;3362}3364Bench& Bench::epochIterations(uint64_t numIters) noexcept {3365mConfig.mEpochIterations = numIters;3366return *this;3367}3368uint64_t Bench::epochIterations() const noexcept {3369return mConfig.mEpochIterations;3370}3372Bench& Bench::warmup(uint64_t numWarmupIters) noexcept {3373mConfig.mWarmup = numWarmupIters;3374return *this;3375}3376uint64_t Bench::warmup() const noexcept {3377return mConfig.mWarmup;3378}3380Bench& Bench::config(Config const& benchmarkConfig) {3381mConfig = benchmarkConfig;3382return *this;3383}3384Config const& Bench::config() const noexcept {3385return mConfig;3386}3388Bench& Bench::output(std::ostream* outstream) noexcept {3389mConfig.mOut = outstream;3390return *this;3391}3393ANKERL_NANOBENCH(NODISCARD) std::ostream* Bench::output() const noexcept {3394return mConfig.mOut;3395}3397std::vector<Result> const& Bench::results() const noexcept {3398return mResults;3399}3401Bench& Bench::render(char const* templateContent, std::ostream& os) {3402::ankerl::nanobench::render(templateContent, *this, os);3403return *this;3404}3406Bench& Bench::render(std::string const& templateContent, std::ostream& os) {3407::ankerl::nanobench::render(templateContent, *this, os);3408return *this;3409}3411std::vector<BigO> Bench::complexityBigO() const {3412std::vector<BigO> bigOs;3413auto rangeMeasure = BigO::collectRangeMeasure(mResults);3414bigOs.emplace_back("O(1)", rangeMeasure, [](double) {3415return 1.0;3416});3417bigOs.emplace_back("O(n)", rangeMeasure, [](double n) {3418return n;3419});3420bigOs.emplace_back("O(log n)", rangeMeasure, [](double n) {3421return std::log2(n);3422});3423bigOs.emplace_back("O(n log n)", rangeMeasure, [](double n) {3424return n * std::log2(n);3425});3426bigOs.emplace_back("O(n^2)", rangeMeasure, [](double n) {3427return n * n;3428});3429bigOs.emplace_back("O(n^3)", rangeMeasure, [](double n) {3430return n * n * n;3431});3432std::sort(bigOs.begin(), bigOs.end());3433return bigOs;3434}3436Rng::Rng()3437: mX(0)3438, mY(0) {3439std::random_device rd;3440std::uniform_int_distribution<uint64_t> dist;3441do {3442mX = dist(rd);3443mY = dist(rd);3444} while (mX == 0 && mY == 0);3445}3447ANKERL_NANOBENCH_NO_SANITIZE("integer", "undefined")3448uint64_t splitMix64(uint64_t& state) noexcept {3449uint64_t z = (state += UINT64_C(0x9e3779b97f4a7c15));3450z = (z ^ (z >> 30U)) * UINT64_C(0xbf58476d1ce4e5b9);3451z = (z ^ (z >> 27U)) * UINT64_C(0x94d049bb133111eb);3452return z ^ (z >> 31U);3453}3455// Seeded as described in romu paper (update april 2020)3456Rng::Rng(uint64_t seed) noexcept3457: mX(splitMix64(seed))3458, mY(splitMix64(seed)) {3459for (size_t i = 0; i < 10; ++i) {3460operator()();3461}3462}3464// only internally used to copy the RNG.3465Rng::Rng(uint64_t x, uint64_t y) noexcept3466: mX(x)3467, mY(y) {}3469Rng Rng::copy() const noexcept {3470return Rng{mX, mY};3471}3473Rng::Rng(std::vector<uint64_t> const& data)3474: mX(0)3475, mY(0) {3476if (data.size() != 2) {3477throw std::runtime_error("ankerl::nanobench::Rng::Rng: needed exactly 2 entries in data, but got " +3478detail::fmt::to_s(data.size()));3479}3480mX = data[0];3481mY = data[1];3482}3484std::vector<uint64_t> Rng::state() const {3485std::vector<uint64_t> data(2);3486data[0] = mX;3487data[1] = mY;3488return data;3489}3491BigO::RangeMeasure BigO::collectRangeMeasure(std::vector<Result> const& results) {3492BigO::RangeMeasure rangeMeasure;3493for (auto const& result : results) {3494if (result.config().mComplexityN > 0.0) {3495rangeMeasure.emplace_back(result.config().mComplexityN, result.median(Result::Measure::elapsed));3496}3497}3498return rangeMeasure;3499}
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.