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.
1751// if (std::regex_match(n.begin, n.end, matchResult, regOpArg1)) {1752std::vector<std::string> matchResult;1753if (matchCmdArgs(std::string(n.begin, n.end), matchResult)) {1754if (matchResult.size() == 2) {1755if (matchResult[0] == "context") {1756return out << r.context(matchResult[1]);1757}1759auto m = Result::fromString(matchResult[1]);1760if (m == Result::Measure::_size) {1761return out << 0.0;1762}1764if (matchResult[0] == "median") {1765return out << r.median(m);1766}1767if (matchResult[0] == "average") {1768return out << r.average(m);1769}1770if (matchResult[0] == "medianAbsolutePercentError") {1771return out << r.medianAbsolutePercentError(m);1772}1773if (matchResult[0] == "sum") {1774return out << r.sum(m);1775}1776if (matchResult[0] == "minimum") {1777return out << r.minimum(m);1778}1779if (matchResult[0] == "maximum") {1780return out << r.maximum(m);1781}1782} else if (matchResult.size() == 3) {1783auto m1 = Result::fromString(matchResult[1]);1784auto m2 = Result::fromString(matchResult[2]);1785if (m1 == Result::Measure::_size || m2 == Result::Measure::_size) {1786return out << 0.0;1787}1789if (matchResult[0] == "sumProduct") {1790return out << r.sumProduct(m1, m2);1791}1792}1793}1795// match e.g. "sumProduct(elapsed, iterations)"1796// static std::regex const regOpArg2("^([a-zA-Z]+)\\(([a-zA-Z]*)\\s*,\\s+([a-zA-Z]*)\\)$");1798// nothing matches :(1799throw std::runtime_error("command '" + std::string(n.begin, n.end) + "' not understood");1800}1802static void generateResultMeasurement(std::vector<Node> const& nodes, size_t idx, Result const& r, std::ostream& out) {1803for (auto const& n : nodes) {1804if (!generateFirstLast(n, idx, r.size(), out)) {1805ANKERL_NANOBENCH_LOG("n.type=" << static_cast<int>(n.type));1806switch (n.type) {1807case Node::Type::content:1808out.write(n.begin, std::distance(n.begin, n.end));1809break;1811case Node::Type::inverted_section:1812throw std::runtime_error("got a inverted section inside measurement");1814case Node::Type::section:1815throw std::runtime_error("got a section inside measurement");1817case Node::Type::tag: {1818auto m = Result::fromString(std::string(n.begin, n.end));1819if (m == Result::Measure::_size || !r.has(m)) {1820out << 0.0;1821} else {1822out << r.get(idx, m);1823}1824break;1825}1826}1827}1828}1829}1831static void generateResult(std::vector<Node> const& nodes, size_t idx, std::vector<Result> const& results, std::ostream& out) {1832auto const& r = results[idx];1833for (auto const& n : nodes) {1834if (!generateFirstLast(n, idx, results.size(), out)) {1835ANKERL_NANOBENCH_LOG("n.type=" << static_cast<int>(n.type));1836switch (n.type) {1837case Node::Type::content:1838out.write(n.begin, std::distance(n.begin, n.end));1839break;1841case Node::Type::inverted_section:1842throw std::runtime_error("got a inverted section inside result");1844case Node::Type::section:1845if (n == "measurement") {1846for (size_t i = 0; i < r.size(); ++i) {1847generateResultMeasurement(n.children, i, r, out);1848}1849} else {1850throw std::runtime_error("got a section inside result");1851}1852break;1854case Node::Type::tag:1855generateResultTag(n, r, out);1856break;1857}1858}1859}1860}1862} // namespace templates1864// helper stuff that only intended to be used internally1865namespace detail {1867char const* getEnv(char const* name);1868bool isEndlessRunning(std::string const& name);1869bool isWarningsEnabled();1871template <typename T>1872T parseFile(std::string const& filename, bool* fail);1874void gatherStabilityInformation(std::vector<std::string>& warnings, std::vector<std::string>& recommendations);1875void printStabilityInformationOnce(std::ostream* outStream);1877// remembers the last table settings used. When it changes, a new table header is automatically written for the new entry.1878uint64_t& singletonHeaderHash() noexcept;1880// determines resolution of the given clock. This is done by measuring multiple times and returning the minimum time difference.1881Clock::duration calcClockResolution(size_t numEvaluations) noexcept;1883// formatting utilities1884namespace fmt {1886// adds thousands separator to numbers1887ANKERL_NANOBENCH(IGNORE_PADDED_PUSH)1888class NumSep : public std::numpunct<char> {1889public:1890explicit NumSep(char sep);1891char do_thousands_sep() const override;1892std::string do_grouping() const override;1894private:1895char mSep;1896};1897ANKERL_NANOBENCH(IGNORE_PADDED_POP)1899// RAII to save & restore a stream's state1900ANKERL_NANOBENCH(IGNORE_PADDED_PUSH)1901class StreamStateRestorer {1902public:1903explicit StreamStateRestorer(std::ostream& s);1904~StreamStateRestorer();1906// sets back all stream info that we remembered at construction1907void restore();1909// don't allow copying / moving1910StreamStateRestorer(StreamStateRestorer const&) = delete;1911StreamStateRestorer& operator=(StreamStateRestorer const&) = delete;1912StreamStateRestorer(StreamStateRestorer&&) = delete;1913StreamStateRestorer& operator=(StreamStateRestorer&&) = delete;1915private:1916std::ostream& mStream;1917std::locale mLocale;1918std::streamsize const mPrecision;1919std::streamsize const mWidth;1920std::ostream::char_type const mFill;1921std::ostream::fmtflags const mFmtFlags;1922};1923ANKERL_NANOBENCH(IGNORE_PADDED_POP)1925// Number formatter1926class Number {1927public:1928Number(int width, int precision, double value);1929Number(int width, int precision, int64_t value);1930ANKERL_NANOBENCH(NODISCARD) std::string to_s() const;1932private:1933friend std::ostream& operator<<(std::ostream& os, Number const& n);1934std::ostream& write(std::ostream& os) const;1936int mWidth;1937int mPrecision;1938double mValue;1939};1941// helper replacement for std::to_string of signed/unsigned numbers so we are locale independent1942std::string to_s(uint64_t n);1944std::ostream& operator<<(std::ostream& os, Number const& n);1946class MarkDownColumn {1947public:1948MarkDownColumn(int w, int prec, std::string tit, std::string suff, double val) noexcept;1949ANKERL_NANOBENCH(NODISCARD) std::string title() const;1950ANKERL_NANOBENCH(NODISCARD) std::string separator() const;1951ANKERL_NANOBENCH(NODISCARD) std::string invalid() const;1952ANKERL_NANOBENCH(NODISCARD) std::string value() const;1954private:1955int mWidth;1956int mPrecision;1957std::string mTitle;1958std::string mSuffix;1959double mValue;1960};1962// Formats any text as markdown code, escaping backticks.1963class MarkDownCode {1964public:1965explicit MarkDownCode(std::string const& what);1967private:1968friend std::ostream& operator<<(std::ostream& os, MarkDownCode const& mdCode);1969std::ostream& write(std::ostream& os) const;1971std::string mWhat{};1972};1974std::ostream& operator<<(std::ostream& os, MarkDownCode const& mdCode);1976} // namespace fmt1977} // namespace detail1978} // namespace nanobench1979} // namespace ankerl1981// implementation /////////////////////////////////////////////////////////////////////////////////1983namespace ankerl {1984namespace nanobench {1986// NOLINTNEXTLINE(readability-function-cognitive-complexity)1987void render(char const* mustacheTemplate, std::vector<Result> const& results, std::ostream& out) {1988detail::fmt::StreamStateRestorer const restorer(out);1990out.precision(std::numeric_limits<double>::digits10);1991auto nodes = templates::parseMustacheTemplate(&mustacheTemplate);1993for (auto const& n : nodes) {1994ANKERL_NANOBENCH_LOG("n.type=" << static_cast<int>(n.type));1995switch (n.type) {1996case templates::Node::Type::content:1997out.write(n.begin, std::distance(n.begin, n.end));1998break;2000case templates::Node::Type::inverted_section:
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.