Skip to content

Commit 4d97ae8

Browse files
committed
bench: reset pool allocator maps
The pool map benchmarks cleared their maps inside the timed call but reused the grown bucket state. That changed the insertion preconditions for later iterations. The benchmark keeps the same reviewer check in place. It records the reset bucket count and asserts that each timed call starts from that same bucket layout. That fails on the old code on the second timed call. Reset the maps in `setup()` with `rehash(0)` so each timed call starts from the same empty bucket layout.
1 parent 159d769 commit 4d97ae8

1 file changed

Lines changed: 17 additions & 12 deletions

File tree

src/bench/pool.cpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <bench/bench.h>
66
#include <support/allocators/pool.h>
77

8+
#include <cassert>
89
#include <cstddef>
910
#include <cstdint>
1011
#include <functional>
@@ -15,18 +16,22 @@ template <typename Map>
1516
void BenchFillClearMap(benchmark::Bench& bench, Map& map)
1617
{
1718
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-
// assert(map.bucket_count() == 0);
24-
auto rng = ankerl::nanobench::Rng(1234);
25-
for (size_t i = 0; i < batch_size; ++i) {
26-
map[rng()];
27-
}
28-
map.clear();
29-
});
19+
size_t reset_bucket_count = 0;
20+
21+
// Each timed call inserts batch_size keys into a freshly reset map.
22+
bench.batch(batch_size).epochIterations(1)
23+
.setup([&] {
24+
map.clear();
25+
map.rehash(0);
26+
reset_bucket_count = map.bucket_count();
27+
})
28+
.run([&] {
29+
assert(map.bucket_count() == reset_bucket_count);
30+
auto rng = ankerl::nanobench::Rng(1234);
31+
for (size_t i = 0; i < batch_size; ++i) {
32+
map[rng()];
33+
}
34+
});
3035
}
3136

3237
static void PoolAllocator_StdUnorderedMap(benchmark::Bench& bench)

0 commit comments

Comments
 (0)