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.
3501BigO::BigO(std::string bigOName, RangeMeasure const& rangeMeasure)3502: mName(std::move(bigOName)) {3504// estimate the constant factor3505double sumRangeMeasure = 0.0;3506double sumRangeRange = 0.0;3508for (const auto& rm : rangeMeasure) {3509sumRangeMeasure += rm.first * rm.second;3510sumRangeRange += rm.first * rm.first;3511}3512mConstant = sumRangeMeasure / sumRangeRange;3514// calculate root mean square3515double err = 0.0;3516double sumMeasure = 0.0;3517for (const auto& rm : rangeMeasure) {3518auto diff = mConstant * rm.first - rm.second;3519err += diff * diff;3521sumMeasure += rm.second;3522}3524auto n = detail::d(rangeMeasure.size());3525auto mean = sumMeasure / n;3526mNormalizedRootMeanSquare = std::sqrt(err / n) / mean;3527}3529BigO::BigO(const char* bigOName, RangeMeasure const& rangeMeasure)3530: BigO(std::string(bigOName), rangeMeasure) {}3532std::string const& BigO::name() const noexcept {3533return mName;3534}3536double BigO::constant() const noexcept {3537return mConstant;3538}3540double BigO::normalizedRootMeanSquare() const noexcept {3541return mNormalizedRootMeanSquare;3542}3544bool BigO::operator<(BigO const& other) const noexcept {3545return std::tie(mNormalizedRootMeanSquare, mName) < std::tie(other.mNormalizedRootMeanSquare, other.mName);3546}3548std::ostream& operator<<(std::ostream& os, BigO const& bigO) {3549return os << bigO.constant() << " * " << bigO.name() << ", rms=" << bigO.normalizedRootMeanSquare();3550}3552std::ostream& operator<<(std::ostream& os, std::vector<ankerl::nanobench::BigO> const& bigOs) {3553detail::fmt::StreamStateRestorer const restorer(os);3554os << std::endl << "| coefficient | err% | complexity" << std::endl << "|--------------:|-------:|------------" << std::endl;3555for (auto const& bigO : bigOs) {3556os << "|" << std::setw(14) << std::setprecision(7) << std::scientific << bigO.constant() << " ";3557os << "|" << detail::fmt::Number(6, 1, bigO.normalizedRootMeanSquare() * 100.0) << "% ";3558os << "| " << bigO.name();3559os << std::endl;3560}3561return os;3562}3564} // namespace nanobench3565} // namespace ankerl3567// NOLINTEND(misc-definitions-in-headers)3568#endif // ANKERL_NANOBENCH_IMPLEMENT3569#endif // ANKERL_NANOBENCH_H_INCLUDED
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.