[libc++] Don't call key_eq in unordered_map/set rehashing routine
As of now containers key_eq might get called when rehashing happens, which is redundant for unique keys containers.
Reviewed By: #libc, philnik, Mordante
Differential Revision: https://reviews.llvm.org/D128021
NOKEYCHECK=True
GitOrigin-RevId: 3085e42f80ac09e53864380ea1c71f3adb643d7c
diff --git a/benchmarks/ContainerBenchmarks.h b/benchmarks/ContainerBenchmarks.h
index d2061f2..f64869a 100644
--- a/benchmarks/ContainerBenchmarks.h
+++ b/benchmarks/ContainerBenchmarks.h
@@ -135,6 +135,20 @@
}
}
+template <class Container, class GenInputs>
+static void BM_Rehash(benchmark::State& st, Container c, GenInputs gen) {
+ auto in = gen(st.range(0));
+ c.max_load_factor(3.0);
+ c.insert(in.begin(), in.end());
+ benchmark::DoNotOptimize(c);
+ const auto bucket_count = c.bucket_count();
+ while (st.KeepRunning()) {
+ c.rehash(bucket_count + 1);
+ c.rehash(bucket_count);
+ benchmark::ClobberMemory();
+ }
+}
+
} // end namespace ContainerBenchmarks
#endif // BENCHMARK_CONTAINER_BENCHMARKS_H