Bitcoin Core
31.1.0
P2P Digital Currency
Toggle main menu visibility
Loading...
Searching...
No Matches
src
bench
pool.cpp
Go to the documentation of this file.
1
// Copyright (c) 2022-present 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
>
6
#include <
support/allocators/pool.h
>
7
8
#include <cstddef>
9
#include <cstdint>
10
#include <functional>
11
#include <unordered_map>
12
#include <utility>
13
14
template
<
typename
Map>
15
void
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
31
static
void
PoolAllocator_StdUnorderedMap
(
benchmark::Bench
& bench)
32
{
33
auto
map = std::unordered_map<uint64_t, uint64_t>();
34
BenchFillClearMap
(bench, map);
35
}
36
37
static
void
PoolAllocator_StdUnorderedMapWithPoolResource
(
benchmark::Bench
& bench)
38
{
39
using
Map = std::unordered_map<uint64_t,
40
uint64_t,
41
std::hash<uint64_t>,
42
std::equal_to<uint64_t>,
43
PoolAllocator<std::pair<const uint64_t, 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
52
BENCHMARK
(
PoolAllocator_StdUnorderedMap
);
53
BENCHMARK
(
PoolAllocator_StdUnorderedMapWithPoolResource
);
bench.h
BENCHMARK
#define BENCHMARK(n)
Definition
bench.h:68
PoolAllocator
Forwards all allocations/deallocations to the PoolResource.
Definition
pool.h:290
ankerl::nanobench::Bench
Main entry point to nanobench's benchmarking facility.
Definition
nanobench.h:627
ankerl::nanobench::Bench::run
Bench & run(char const *benchmarkName, Op &&op)
Repeatedly calls op() based on the configuration, and performs measurements.
Definition
nanobench.h:1234
ankerl::nanobench::Bench::batch
Bench & batch(T b) noexcept
Sets the batch size.
Definition
nanobench.h:1258
ankerl::nanobench::Bench::minEpochIterations
ANKERL_NANOBENCH(NODISCARD) std Bench & minEpochIterations(uint64_t numIters) noexcept
Sets the minimum number of iterations each epoch should take.
ankerl::nanobench::Rng
An extremely fast random generator.
Definition
nanobench.h:488
BenchFillClearMap
void BenchFillClearMap(benchmark::Bench &bench, Map &map)
Definition
pool.cpp:15
PoolAllocator_StdUnorderedMapWithPoolResource
static void PoolAllocator_StdUnorderedMapWithPoolResource(benchmark::Bench &bench)
Definition
pool.cpp:37
PoolAllocator_StdUnorderedMap
static void PoolAllocator_StdUnorderedMap(benchmark::Bench &bench)
Definition
pool.cpp:31
pool.h
Generated on
for Bitcoin Core by
1.17.0