Bitcoin ABC 0.30.7
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 <unordered_map>
9
10template <typename Map>
11void BenchFillClearMap(benchmark::Bench &bench, Map &map) {
12 size_t batch_size = 5000;
13
14 // make sure each iteration of the benchmark contains exactly 5000 inserts
15 // and one clear.
16 // do this at least 10 times so we get reasonable accurate results
17
18 bench.batch(batch_size).minEpochIterations(10).run([&] {
19 auto rng = ankerl::nanobench::Rng(1234);
20 for (size_t i = 0; i < batch_size; ++i) {
21 map[rng()];
22 }
23 map.clear();
24 });
25}
26
28 auto map = std::unordered_map<uint64_t, uint64_t>();
29 BenchFillClearMap(bench, map);
30}
31
32static void
34 using Map = std::unordered_map<
35 uint64_t, uint64_t, std::hash<uint64_t>, std::equal_to<uint64_t>,
37 sizeof(std::pair<const uint64_t, uint64_t>) +
38 4 * sizeof(void *)>>;
39
40 // make sure the resource supports large enough pools to hold the node.
41 // We do this by adding the size of a few pointers to it.
42 auto pool_resource = Map::allocator_type::ResourceType();
43 auto map = Map{0, std::hash<uint64_t>{}, std::equal_to<uint64_t>{},
44 &pool_resource};
45 BenchFillClearMap(bench, map);
46}
47
Forwards all allocations/deallocations to the PoolResource.
Definition: pool.h:299
Main entry point to nanobench's benchmarking facility.
Definition: nanobench.h:616
ANKERL_NANOBENCH(NODISCARD) std Bench & batch(T b) noexcept
Sets the batch size.
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition: nanobench.h:1183
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:477
void BenchFillClearMap(benchmark::Bench &bench, Map &map)
Definition: pool.cpp:11
static void PoolAllocator_StdUnorderedMapWithPoolResource(benchmark::Bench &bench)
Definition: pool.cpp:33
static void PoolAllocator_StdUnorderedMap(benchmark::Bench &bench)
Definition: pool.cpp:27
BENCHMARK(PoolAllocator_StdUnorderedMap)