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) 2022-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 <support/allocators/pool.h>8#include <cstddef>9#include <cstdint>10#include <functional>11#include <unordered_map>12#include <utility>14template <typename Map>15void BenchFillClearMap(benchmark::Bench& bench, Map& map)16{17size_t batch_size = 5000;19// make sure each iteration of the benchmark contains exactly 5000 inserts and one clear.20// do this at least 10 times so we get reasonable accurate results22bench.batch(batch_size).minEpochIterations(10).run([&] {23auto rng = ankerl::nanobench::Rng(1234);24for (size_t i = 0; i < batch_size; ++i) {25map[rng()];26}27map.clear();28});29}31static void PoolAllocator_StdUnorderedMap(benchmark::Bench& bench)32{33auto map = std::unordered_map<uint64_t, uint64_t>();34BenchFillClearMap(bench, map);35}37static void PoolAllocator_StdUnorderedMapWithPoolResource(benchmark::Bench& bench)38{39using Map = std::unordered_map<uint64_t,40uint64_t,41std::hash<uint64_t>,42std::equal_to<uint64_t>,43PoolAllocator<std::pair<const uint64_t, uint64_t>,44sizeof(std::pair<const uint64_t, uint64_t>) + 4 * sizeof(void*)>>;46// make sure the resource supports large enough pools to hold the node. We do this by adding the size of a few pointers to it.47auto pool_resource = Map::allocator_type::ResourceType();48auto map = Map{0, std::hash<uint64_t>{}, std::equal_to<uint64_t>{}, &pool_resource};49BenchFillClearMap(bench, map);50}52BENCHMARK(PoolAllocator_StdUnorderedMap);53BENCHMARK(PoolAllocator_StdUnorderedMapWithPoolResource);
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.