diff options
author | Abseil Team <absl-team@google.com> | 2022-09-13 23:27:41 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2022-09-13 23:28:17 -0700 |
commit | 1be36c8a50e1c2aae525c0fa95cb300ecf9abbe4 (patch) | |
tree | d457f1c9b0c41c0551d80ac23e09ee14540669e6 /absl/container/internal/raw_hash_set_benchmark.cc | |
parent | dc6109e0c8b2f6ba0fde389050ff6de6c9a082e7 (diff) |
Change `EndComparison` benchmark to not measure iteration. Also added `BM_Iteration` separately.
```
BM_EndComparison 0.46ns ± 0%
BM_Iteration/10/10 8.09ns ± 7%
BM_Iteration/20/20 18.6ns ±16%
BM_Iteration/100/100 79.0ns ±15%
BM_Iteration/400/400 344ns ± 5%
BM_Iteration/100/1 16.6ns ± 1%
BM_Iteration/1000/10 454ns ± 3%
```
PiperOrigin-RevId: 474211728
Change-Id: I9bd799a4be3247ca8f2a2144b6e857db8c99c81f
Diffstat (limited to 'absl/container/internal/raw_hash_set_benchmark.cc')
-rw-r--r-- | absl/container/internal/raw_hash_set_benchmark.cc | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/absl/container/internal/raw_hash_set_benchmark.cc b/absl/container/internal/raw_hash_set_benchmark.cc index 47dc9048..fdec769b 100644 --- a/absl/container/internal/raw_hash_set_benchmark.cc +++ b/absl/container/internal/raw_hash_set_benchmark.cc @@ -12,13 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -#include "absl/container/internal/raw_hash_set.h" - #include <numeric> #include <random> +#include <vector> #include "absl/base/internal/raw_logging.h" #include "absl/container/internal/hash_function_defaults.h" +#include "absl/container/internal/raw_hash_set.h" #include "absl/strings/str_format.h" #include "benchmark/benchmark.h" @@ -202,23 +202,46 @@ void CacheInSteadyStateArgs(Benchmark* bm) { BENCHMARK(BM_CacheInSteadyState)->Apply(CacheInSteadyStateArgs); void BM_EndComparison(benchmark::State& state) { + StringTable t = {{"a", "a"}, {"b", "b"}}; + auto it = t.begin(); + for (auto i : state) { + benchmark::DoNotOptimize(t); + benchmark::DoNotOptimize(it); + benchmark::DoNotOptimize(it != t.end()); + } +} +BENCHMARK(BM_EndComparison); + +void BM_Iteration(benchmark::State& state) { std::random_device rd; std::mt19937 rng(rd()); string_generator gen{12}; StringTable t; - while (t.size() < state.range(0)) { + + size_t capacity = state.range(0); + size_t size = state.range(1); + t.reserve(capacity); + + while (t.size() < size) { t.emplace(gen(rng), gen(rng)); } - for (auto _ : state) { + for (auto i : state) { + benchmark::DoNotOptimize(t); for (auto it = t.begin(); it != t.end(); ++it) { - benchmark::DoNotOptimize(it); - benchmark::DoNotOptimize(t); - benchmark::DoNotOptimize(it != t.end()); + benchmark::DoNotOptimize(*it); } } } -BENCHMARK(BM_EndComparison)->Arg(400); + +BENCHMARK(BM_Iteration) + ->ArgPair(10, 10) + ->ArgPair(20, 20) + ->ArgPair(100, 100) + ->ArgPair(400, 400) + // sparse + ->ArgPair(100, 1) + ->ArgPair(1000, 10); void BM_CopyCtor(benchmark::State& state) { std::random_device rd; @@ -437,7 +460,6 @@ void CodegenAbslRawHashSetInt64Iterate( int odr = (::benchmark::DoNotOptimize(std::make_tuple( &CodegenAbslRawHashSetInt64Find, &CodegenAbslRawHashSetInt64FindNeEnd, - &CodegenAbslRawHashSetInt64Insert, - &CodegenAbslRawHashSetInt64Contains, + &CodegenAbslRawHashSetInt64Insert, &CodegenAbslRawHashSetInt64Contains, &CodegenAbslRawHashSetInt64Iterate)), 1); |