mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 20:45:14 +00:00
Tests: Introduce a HashTable benchmark for "table thrashing"
Thrashing is what I call the situations where a table is mostly filled with deleted markers, causing an increase in size (at least temporarily) when a simple re-hash would be enough to get rid of those. This happens when a hash table (especially with many elements) has a lot of deletes and re-inserts done to it, which is what this benchmark does.
This commit is contained in:
parent
bcb8937898
commit
e73e579446
Notes:
sideshowbarker
2024-07-17 16:26:17 +09:00
Author: https://github.com/kleinesfilmroellchen Commit: https://github.com/SerenityOS/serenity/commit/e73e579446 Pull-request: https://github.com/SerenityOS/serenity/pull/12937 Reviewed-by: https://github.com/Hendiadyoin1 Reviewed-by: https://github.com/davidot
1 changed files with 18 additions and 0 deletions
|
@ -234,3 +234,21 @@ TEST_CASE(capacity_leak)
|
|||
}
|
||||
EXPECT(table.capacity() < 100u);
|
||||
}
|
||||
|
||||
// Inserting and removing a bunch of elements will "thrash" the table, leading to a lot of "deleted" markers.
|
||||
BENCHMARK_CASE(benchmark_thrashing)
|
||||
{
|
||||
HashTable<int> table;
|
||||
// Ensure that there needs to be some copying when rehashing.
|
||||
table.set(3);
|
||||
table.set(7);
|
||||
table.set(11);
|
||||
table.set(13);
|
||||
for (int i = 0; i < 10'000; ++i) {
|
||||
table.set(-i);
|
||||
}
|
||||
for (int i = 0; i < 10'000'000; ++i) {
|
||||
table.set(i);
|
||||
table.remove(i);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue