Commit fbd5fa17 by Vitaly Goldshteyn Committed by Copybara-Service

Fix bug in BM_EraseIf.

PiperOrigin-RevId: 621258501
Change-Id: Id094f3f0d0bc4a9fa8f3d1f90cfcd4c53beeb776
parent 5953a488
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <cmath> #include <cmath>
#include <cstddef> #include <cstddef>
#include <cstdint> #include <cstdint>
#include <limits>
#include <numeric> #include <numeric>
#include <random> #include <random>
#include <string> #include <string>
...@@ -593,14 +594,17 @@ void BM_EraseIf(benchmark::State& state) { ...@@ -593,14 +594,17 @@ void BM_EraseIf(benchmark::State& state) {
auto& table = tables.back(); auto& table = tables.back();
for (int64_t i = 0; i < num_elements; i++) { for (int64_t i = 0; i < num_elements; i++) {
// We use random keys to reduce noise. // We use random keys to reduce noise.
k.push_back(absl::Uniform<int64_t>(rng, 0, ~int64_t{})); k.push_back(
absl::Uniform<int64_t>(rng, 0, std::numeric_limits<int64_t>::max()));
if (!table.insert(k.back()).second) { if (!table.insert(k.back()).second) {
k.pop_back(); k.pop_back();
--i; // duplicated value, retrying --i; // duplicated value, retrying
} }
} }
std::sort(k.begin(), k.end()); std::sort(k.begin(), k.end());
threshold.push_back(k[num_erased]); threshold.push_back(static_cast<int64_t>(num_erased) < num_elements
? k[num_erased]
: std::numeric_limits<int64_t>::max());
} }
while (state.KeepRunningBatch(static_cast<int64_t>(kRepetitions) * while (state.KeepRunningBatch(static_cast<int64_t>(kRepetitions) *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment