Skip to content

Commit

Permalink
Create and destroy tables outside of the timer and in batch in Reserv…
Browse files Browse the repository at this point in the history
…e benchmarks.

PiperOrigin-RevId: 592483250
Change-Id: I55fa9982c4dbc723b30957cb31da95251e368707
  • Loading branch information
Abseil Team authored and copybara-github committed Dec 20, 2023
1 parent 1ae1207 commit b559abc
Showing 1 changed file with 26 additions and 12 deletions.
38 changes: 26 additions & 12 deletions absl/container/internal/raw_hash_set_benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down

0 comments on commit b559abc

Please sign in to comment.