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.
1501]1502}1503]1504}1505],1506"metadata": {1507"loops": {{sum(iterations)}},1508"inner_loops": {{batch}},1509"name": "{{title}}",1510"unit": "second"1511},1512"version": "1.0"1513})DELIM";1514}1516char const* json() noexcept {1517return R"DELIM({1518"results": [1519{{#result}} {1520"title": "{{title}}",1521"name": "{{name}}",1522"unit": "{{unit}}",1523"batch": {{batch}},1524"complexityN": {{complexityN}},1525"epochs": {{epochs}},1526"clockResolution": {{clockResolution}},1527"clockResolutionMultiple": {{clockResolutionMultiple}},1528"maxEpochTime": {{maxEpochTime}},1529"minEpochTime": {{minEpochTime}},1530"minEpochIterations": {{minEpochIterations}},1531"epochIterations": {{epochIterations}},1532"warmup": {{warmup}},1533"relative": {{relative}},1534"median(elapsed)": {{median(elapsed)}},1535"medianAbsolutePercentError(elapsed)": {{medianAbsolutePercentError(elapsed)}},1536"median(instructions)": {{median(instructions)}},1537"medianAbsolutePercentError(instructions)": {{medianAbsolutePercentError(instructions)}},1538"median(cpucycles)": {{median(cpucycles)}},1539"median(contextswitches)": {{median(contextswitches)}},1540"median(pagefaults)": {{median(pagefaults)}},1541"median(branchinstructions)": {{median(branchinstructions)}},1542"median(branchmisses)": {{median(branchmisses)}},1543"totalTime": {{sumProduct(iterations, elapsed)}},1544"measurements": [1545{{#measurement}} {1546"iterations": {{iterations}},1547"elapsed": {{elapsed}},1548"pagefaults": {{pagefaults}},1549"cpucycles": {{cpucycles}},1550"contextswitches": {{contextswitches}},1551"instructions": {{instructions}},1552"branchinstructions": {{branchinstructions}},1553"branchmisses": {{branchmisses}}1554}{{^-last}},{{/-last}}1555{{/measurement}} ]1556}{{^-last}},{{/-last}}1557{{/result}} ]1558})DELIM";1559}1561ANKERL_NANOBENCH(IGNORE_PADDED_PUSH)1562struct Node {1563enum class Type { tag, content, section, inverted_section };1565char const* begin;1566char const* end;1567std::vector<Node> children;1568Type type;1570template <size_t N>1571// NOLINTNEXTLINE(hicpp-avoid-c-arrays,modernize-avoid-c-arrays,cppcoreguidelines-avoid-c-arrays)1572bool operator==(char const (&str)[N]) const noexcept {1573// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-array-to-pointer-decay)1574return static_cast<size_t>(std::distance(begin, end) + 1) == N && 0 == strncmp(str, begin, N - 1);1575}1576};1577ANKERL_NANOBENCH(IGNORE_PADDED_POP)1579// NOLINTNEXTLINE(misc-no-recursion)1580static std::vector<Node> parseMustacheTemplate(char const** tpl) {1581std::vector<Node> nodes;1583while (true) {1584auto const* begin = std::strstr(*tpl, "{{");1585auto const* end = begin;1586if (begin != nullptr) {1587// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)1588begin += 2;1589end = std::strstr(begin, "}}");1590}1592if (begin == nullptr || end == nullptr) {1593// nothing found, finish node1594// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)1595nodes.emplace_back(Node{*tpl, *tpl + std::strlen(*tpl), std::vector<Node>{}, Node::Type::content});1596return nodes;1597}1599// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)1600nodes.emplace_back(Node{*tpl, begin - 2, std::vector<Node>{}, Node::Type::content});1602// we found a tag1603// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)1604*tpl = end + 2;1605switch (*begin) {1606case '/':1607// finished! bail out1608return nodes;1610case '#':1611// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)1612nodes.emplace_back(Node{begin + 1, end, parseMustacheTemplate(tpl), Node::Type::section});1613break;1615case '^':1616// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)1617nodes.emplace_back(Node{begin + 1, end, parseMustacheTemplate(tpl), Node::Type::inverted_section});1618break;1620default:1621nodes.emplace_back(Node{begin, end, std::vector<Node>{}, Node::Type::tag});1622break;1623}1624}1625}1627static bool generateFirstLast(Node const& n, size_t idx, size_t size, std::ostream& out) {1628ANKERL_NANOBENCH_LOG("n.type=" << static_cast<int>(n.type));1629bool const matchFirst = n == "-first";1630bool const matchLast = n == "-last";1631if (!matchFirst && !matchLast) {1632return false;1633}1635bool doWrite = false;1636if (n.type == Node::Type::section) {1637doWrite = (matchFirst && idx == 0) || (matchLast && idx == size - 1);1638} else if (n.type == Node::Type::inverted_section) {1639doWrite = (matchFirst && idx != 0) || (matchLast && idx != size - 1);1640}1642if (doWrite) {1643for (auto const& child : n.children) {1644if (child.type == Node::Type::content) {1645out.write(child.begin, std::distance(child.begin, child.end));1646}1647}1648}1649return true;1650}1652static bool matchCmdArgs(std::string const& str, std::vector<std::string>& matchResult) {1653matchResult.clear();1654auto idxOpen = str.find('(');1655auto idxClose = str.find(')', idxOpen);1656if (idxClose == std::string::npos) {1657return false;1658}1660matchResult.emplace_back(str.substr(0, idxOpen));1662// split by comma1663matchResult.emplace_back();1664for (size_t i = idxOpen + 1; i != idxClose; ++i) {1665if (str[i] == ' ' || str[i] == '\t') {1666// skip whitespace1667continue;1668}1669if (str[i] == ',') {1670// got a comma => new string1671matchResult.emplace_back();1672continue;1673}1674// no whitespace no comma, append1675matchResult.back() += str[i];1676}1677return true;1678}1680static bool generateConfigTag(Node const& n, Config const& config, std::ostream& out) {1681using detail::d;1683if (n == "title") {1684out << config.mBenchmarkTitle;1685return true;1686}1687if (n == "name") {1688out << config.mBenchmarkName;1689return true;1690}1691if (n == "unit") {1692out << config.mUnit;1693return true;1694}1695if (n == "batch") {1696out << config.mBatch;1697return true;1698}1699if (n == "complexityN") {1700out << config.mComplexityN;1701return true;1702}1703if (n == "epochs") {1704out << config.mNumEpochs;1705return true;1706}1707if (n == "clockResolution") {1708out << d(detail::clockResolution());1709return true;1710}1711if (n == "clockResolutionMultiple") {1712out << config.mClockResolutionMultiple;1713return true;1714}1715if (n == "maxEpochTime") {1716out << d(config.mMaxEpochTime);1717return true;1718}1719if (n == "minEpochTime") {1720out << d(config.mMinEpochTime);1721return true;1722}1723if (n == "minEpochIterations") {1724out << config.mMinEpochIterations;1725return true;1726}1727if (n == "epochIterations") {1728out << config.mEpochIterations;1729return true;1730}1731if (n == "warmup") {1732out << config.mWarmup;1733return true;1734}1735if (n == "relative") {1736out << config.mIsRelative;1737return true;1738}1739return false;1740}1742// NOLINTNEXTLINE(readability-function-cognitive-complexity)1743static std::ostream& generateResultTag(Node const& n, Result const& r, std::ostream& out) {1744if (generateConfigTag(n, r.config(), out)) {1745return out;1746}1747// match e.g. "median(elapsed)"1748// g++ 4.8 doesn't implement std::regex :(1749// static std::regex const regOpArg1("^([a-zA-Z]+)\\(([a-zA-Z]*)\\)$");1750// std::cmatch matchResult;
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.