forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
merge bitcoin#25325: Add pool based memory resource
- Loading branch information
Showing
16 changed files
with
1,003 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright (c) 2022 The Bitcoin Core developers | ||
// Distributed under the MIT software license, see the accompanying | ||
// file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
#include <bench/bench.h> | ||
#include <support/allocators/pool.h> | ||
|
||
#include <unordered_map> | ||
|
||
template <typename Map> | ||
void BenchFillClearMap(benchmark::Bench& bench, Map& map) | ||
{ | ||
size_t batch_size = 5000; | ||
|
||
// make sure each iteration of the benchmark contains exactly 5000 inserts and one clear. | ||
// do this at least 10 times so we get reasonable accurate results | ||
|
||
bench.batch(batch_size).minEpochIterations(10).run([&] { | ||
auto rng = ankerl::nanobench::Rng(1234); | ||
for (size_t i = 0; i < batch_size; ++i) { | ||
map[rng()]; | ||
} | ||
map.clear(); | ||
}); | ||
} | ||
|
||
static void PoolAllocator_StdUnorderedMap(benchmark::Bench& bench) | ||
{ | ||
auto map = std::unordered_map<uint64_t, uint64_t>(); | ||
BenchFillClearMap(bench, map); | ||
} | ||
|
||
static void PoolAllocator_StdUnorderedMapWithPoolResource(benchmark::Bench& bench) | ||
{ | ||
using Map = std::unordered_map<uint64_t, | ||
uint64_t, | ||
std::hash<uint64_t>, | ||
std::equal_to<uint64_t>, | ||
PoolAllocator<std::pair<const uint64_t, uint64_t>, | ||
sizeof(std::pair<const uint64_t, uint64_t>) + 4 * sizeof(void*), | ||
alignof(void*)>>; | ||
|
||
// 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. | ||
auto pool_resource = Map::allocator_type::ResourceType(); | ||
auto map = Map{0, std::hash<uint64_t>{}, std::equal_to<uint64_t>{}, &pool_resource}; | ||
BenchFillClearMap(bench, map); | ||
} | ||
|
||
BENCHMARK(PoolAllocator_StdUnorderedMap); | ||
BENCHMARK(PoolAllocator_StdUnorderedMapWithPoolResource); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.