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) 2024-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#include <bench/bench.h>6#include <random.h>7#include <util/check.h>8#include <util/strencodings.h>10#include <cstddef>11#include <optional>12#include <string>14std::string generateHexString(size_t length) {15const auto hex_digits = "0123456789ABCDEF";16FastRandomContext rng(/*fDeterministic=*/true);18std::string data;19while (data.size() < length) {20auto digit = hex_digits[rng.randbits(4)];21data.push_back(digit);22}23return data;24}26static void HexParse(benchmark::Bench& bench)27{28auto data = generateHexString(130); // Generates 678B0EDA0A1FD30904D5A65E3568DB82DB2D918B0AD8DEA18A63FECCB877D07CAD1495C7157584D877420EF38B8DA473A6348B4F51811AC13C786B962BEE5668F9 by default30bench.batch(data.size()).unit("base16").run([&] {31auto result = TryParseHex(data);32assert(result != std::nullopt); // make sure we're measuring the successful case33ankerl::nanobench::doNotOptimizeAway(result);34});35}37BENCHMARK(HexParse);
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.