Bitcoin ABC 0.26.3
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>
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>();
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>{},
46}
47
#define BENCHMARK(n)
Definition bench.h:65
Forwards all allocations/deallocations to the PoolResource.
Definition pool.h:299
Main entry point to nanobench's benchmarking facility.
Definition nanobench.h:616
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
T GetRand(T nMax=std::numeric_limits< T >::max()) noexcept
Generate a uniform random integer of type T in the range [0..nMax) nMax defaults to std::numeric_limi...
Definition random.h:85