summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2023-12-20 01:39:21 -0800
committerGravatar Copybara-Service <copybara-worker@google.com>2023-12-20 01:40:08 -0800
commitb559abcbbe27402b6d6d47db38c23f69ca99aff2 (patch)
tree34dc85eeae789413a44f504f9d8acfcf409ea785
parent1ae120741859e22d5231b25a1295d3806ad5c519 (diff)
Create and destroy tables outside of the timer and in batch in Reserve benchmarks.
PiperOrigin-RevId: 592483250 Change-Id: I55fa9982c4dbc723b30957cb31da95251e368707
-rw-r--r--absl/container/internal/raw_hash_set_benchmark.cc38
1 files changed, 26 insertions, 12 deletions
diff --git a/absl/container/internal/raw_hash_set_benchmark.cc b/absl/container/internal/raw_hash_set_benchmark.cc
index a9b52c4f..88b07373 100644
--- a/absl/container/internal/raw_hash_set_benchmark.cc
+++ b/absl/container/internal/raw_hash_set_benchmark.cc
@@ -387,28 +387,42 @@ void BM_NoOpReserveStringTable(benchmark::State& state) {
BENCHMARK(BM_NoOpReserveStringTable);
void BM_ReserveIntTable(benchmark::State& state) {
- int reserve_size = state.range(0);
- for (auto _ : state) {
+ constexpr size_t kBatchSize = 1024;
+ size_t reserve_size = static_cast<size_t>(state.range(0));
+
+ std::vector<IntTable> tables;
+ while (state.KeepRunningBatch(kBatchSize)) {
state.PauseTiming();
- IntTable t;
+ tables.clear();
+ tables.resize(kBatchSize);
state.ResumeTiming();
- benchmark::DoNotOptimize(t);
- t.reserve(reserve_size);
+ for (auto& t : tables) {
+ benchmark::DoNotOptimize(t);
+ t.reserve(reserve_size);
+ benchmark::DoNotOptimize(t);
+ }
}
}
-BENCHMARK(BM_ReserveIntTable)->Range(128, 4096);
+BENCHMARK(BM_ReserveIntTable)->Range(1, 64);
void BM_ReserveStringTable(benchmark::State& state) {
- int reserve_size = state.range(0);
- for (auto _ : state) {
+ constexpr size_t kBatchSize = 1024;
+ size_t reserve_size = static_cast<size_t>(state.range(0));
+
+ std::vector<StringTable> tables;
+ while (state.KeepRunningBatch(kBatchSize)) {
state.PauseTiming();
- StringTable t;
+ tables.clear();
+ tables.resize(kBatchSize);
state.ResumeTiming();
- benchmark::DoNotOptimize(t);
- t.reserve(reserve_size);
+ for (auto& t : tables) {
+ benchmark::DoNotOptimize(t);
+ t.reserve(reserve_size);
+ benchmark::DoNotOptimize(t);
+ }
}
}
-BENCHMARK(BM_ReserveStringTable)->Range(128, 4096);
+BENCHMARK(BM_ReserveStringTable)->Range(1, 64);
// Like std::iota, except that ctrl_t doesn't support operator++.
template <typename CtrlIter>