summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2023-12-18 12:59:28 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2023-12-18 13:00:17 -0800
commitbae260199fffe782d5a5414bb80cfe49abb1436f (patch)
treef56fd8bef598956f656fa0052b3ca7bc768911b6
parent8900d7c496afb0fb0e0a737d001a46828bc446dd (diff)
Add the `BM_EraseEmplace` benchmark that constantly adds and removes the same element.
PiperOrigin-RevId: 591987002 Change-Id: Ic1ed2063aeb95a6e814eefcbed024e1a5a1d8d2f
-rw-r--r--absl/container/internal/raw_hash_set_benchmark.cc18
1 files changed, 18 insertions, 0 deletions
diff --git a/absl/container/internal/raw_hash_set_benchmark.cc b/absl/container/internal/raw_hash_set_benchmark.cc
index a3647890..a9b52c4f 100644
--- a/absl/container/internal/raw_hash_set_benchmark.cc
+++ b/absl/container/internal/raw_hash_set_benchmark.cc
@@ -14,6 +14,8 @@
#include <array>
#include <cmath>
+#include <cstddef>
+#include <cstdint>
#include <numeric>
#include <random>
#include <tuple>
@@ -205,6 +207,22 @@ void CacheInSteadyStateArgs(Benchmark* bm) {
}
BENCHMARK(BM_CacheInSteadyState)->Apply(CacheInSteadyStateArgs);
+void BM_EraseEmplace(benchmark::State& state) {
+ IntTable t;
+ int64_t size = state.range(0);
+ for (int64_t i = 0; i < size; ++i) {
+ t.emplace(i);
+ }
+ while (state.KeepRunningBatch(size)) {
+ for (int64_t i = 0; i < size; ++i) {
+ benchmark::DoNotOptimize(t);
+ t.erase(i);
+ t.emplace(i);
+ }
+ }
+}
+BENCHMARK(BM_EraseEmplace)->Arg(1)->Arg(2)->Arg(4)->Arg(8)->Arg(16)->Arg(100);
+
void BM_EndComparison(benchmark::State& state) {
StringTable t = {{"a", "a"}, {"b", "b"}};
auto it = t.begin();