From bae260199fffe782d5a5414bb80cfe49abb1436f Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 18 Dec 2023 12:59:28 -0800 Subject: Add the `BM_EraseEmplace` benchmark that constantly adds and removes the same element. PiperOrigin-RevId: 591987002 Change-Id: Ic1ed2063aeb95a6e814eefcbed024e1a5a1d8d2f --- absl/container/internal/raw_hash_set_benchmark.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'absl') 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 #include +#include +#include #include #include #include @@ -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(); -- cgit v1.2.3