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) 2018-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 <bech32.h>6#include <bench/bench.h>7#include <util/strencodings.h>9#include <array>10#include <vector>12using namespace util::hex_literals;14static void Bech32Encode(benchmark::Bench& bench)15{16constexpr std::array<uint8_t, 32> v{"c97f5a67ec381b760aeaf67573bc164845ff39a3bb26a1cee401ac67243b48db"_hex_u8};17std::vector<unsigned char> tmp = {0};18tmp.reserve(1 + v.size() * 8 / 5);19ConvertBits<8, 5, true>([&](unsigned char c) { tmp.push_back(c); }, v.begin(), v.end());20bench.batch(v.size()).unit("byte").run([&] {21bech32::Encode(bech32::Encoding::BECH32, "bc", tmp);22});23}26static void Bech32Decode(benchmark::Bench& bench)27{28std::string addr = "bc1qkallence7tjawwvy0dwt4twc62qjgaw8f4vlhyd006d99f09";29bench.batch(addr.size()).unit("byte").run([&] {30bech32::Decode(addr);31});32}35BENCHMARK(Bech32Encode);36BENCHMARK(Bech32Decode);
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.