Bitcoin Core 28.99.0
P2P Digital Currency
pool.cpp
Go to the documentation of this file.
1// Copyright (c) 2022 The Bitcoin Core developers
2// Distributed under the MIT software license, see the accompanying
3// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5#include <bench/bench.h>
7
8#include <cstddef>
9#include <cstdint>
10#include <functional>
11#include <unordered_map>
12#include <utility>
13
14template <typename Map>
15void BenchFillClearMap(benchmark::Bench& bench, Map& map)
16{
17 size_t batch_size = 5000;
18
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 results
21
22 bench.batch(batch_size).minEpochIterations(10).run([&] {
23 auto rng = ankerl::nanobench::Rng(1234);
24 for (size_t i = 0; i < batch_size; ++i) {
25 map[rng()];
26 }
27 map.clear();
28 });
29}
30
32{
33 auto map = std::unordered_map<uint64_t, uint64_t>();
34 BenchFillClearMap(bench, map);
35}
36
38{
39 using Map = std::unordered_map<uint64_t,
40 uint64_t,
41 std::hash<uint64_t>,
42 std::equal_to<uint64_t>,
44 sizeof(std::pair<const uint64_t, uint64_t>) + 4 * sizeof(void*)>>;
45
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.
47 auto pool_resource = Map::allocator_type::ResourceType();
48 auto map = Map{0, std::hash<uint64_t>{}, std::equal_to<uint64_t>{}, &pool_resource};
49 BenchFillClearMap(bench, map);
50}
51
Forwards all allocations/deallocations to the PoolResource.
Definition: pool.h:277
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:627
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1234
Bench & batch(T b) noexcept
Sets the batch size.
Definition: nanobench.h:1258
ANKERL_NANOBENCH(NODISCARD) std Bench & minEpochIterations(uint64_t numIters) noexcept
Sets the minimum number of iterations each epoch should take.
An extremely fast random generator.
Definition: nanobench.h:488
@ HIGH
Definition: bench.h:48
void BenchFillClearMap(benchmark::Bench &bench, Map &map)
Definition: pool.cpp:15
static void PoolAllocator_StdUnorderedMapWithPoolResource(benchmark::Bench &bench)
Definition: pool.cpp:37
BENCHMARK(PoolAllocator_StdUnorderedMap, benchmark::PriorityLevel::HIGH)
static void PoolAllocator_StdUnorderedMap(benchmark::Bench &bench)
Definition: pool.cpp:31