Bitcoin Core 28.0.0
P2P Digital Currency
Loading...
Searching...
No Matches
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{
13 size_t batch_size = 5000;
14
15 // make sure each iteration of the benchmark contains exactly 5000 inserts 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{
29 auto map = std::unordered_map<uint64_t, uint64_t>();
30 BenchFillClearMap(bench, map);
31}
32
34{
35 using Map = std::unordered_map<uint64_t,
36 uint64_t,
37 std::hash<uint64_t>,
38 std::equal_to<uint64_t>,
40 sizeof(std::pair<const uint64_t, uint64_t>) + 4 * sizeof(void*)>>;
41
42 // 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.
43 auto pool_resource = Map::allocator_type::ResourceType();
44 auto map = Map{0, std::hash<uint64_t>{}, std::equal_to<uint64_t>{}, &pool_resource};
45 BenchFillClearMap(bench, map);
46}
47
#define BENCHMARK(n, priority_level)
Definition bench.h:79
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:47
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