summaryrefslogtreecommitdiff
path: root/absl
diff options
context:
space:
mode:
authorGravatar Abseil Team <absl-team@google.com>2022-09-20 11:04:11 -0700
committerGravatar Copybara-Service <copybara-worker@google.com>2022-09-20 11:04:51 -0700
commit800c04f64afa48271c6eaee67da489a7ebf92757 (patch)
treedb1e8eb5fba65701ba8c534eac6429e240fca234 /absl
parentd4607b3f05f3f22dda383efcb0aba7e7d9359823 (diff)
Add sparse and string copy constructor benchmarks for hash table.
PiperOrigin-RevId: 475601161 Change-Id: I3f67a1597ddfa6de60f19fe4b38d44fbc5630bd8
Diffstat (limited to 'absl')
-rw-r--r--absl/container/internal/raw_hash_set_benchmark.cc48
1 files changed, 43 insertions, 5 deletions
diff --git a/absl/container/internal/raw_hash_set_benchmark.cc b/absl/container/internal/raw_hash_set_benchmark.cc
index 4c61d84c..e17ba9b4 100644
--- a/absl/container/internal/raw_hash_set_benchmark.cc
+++ b/absl/container/internal/raw_hash_set_benchmark.cc
@@ -15,8 +15,8 @@
#include <array>
#include <cmath>
#include <numeric>
-#include <utility>
#include <random>
+#include <utility>
#include <vector>
#include "absl/base/internal/raw_logging.h"
@@ -258,22 +258,60 @@ BENCHMARK(BM_Iteration)
->ArgPair(100, 1)
->ArgPair(1000, 10);
-void BM_CopyCtor(benchmark::State& state) {
+void BM_CopyCtorSparseInt(benchmark::State& state) {
std::random_device rd;
std::mt19937 rng(rd());
IntTable t;
std::uniform_int_distribution<uint64_t> dist(0, ~uint64_t{});
- while (t.size() < state.range(0)) {
+ size_t size = state.range(0);
+ t.reserve(size * 10);
+ while (t.size() < size) {
t.emplace(dist(rng));
}
- for (auto _ : state) {
+ for (auto i : state) {
+ IntTable t2 = t;
+ benchmark::DoNotOptimize(t2);
+ }
+}
+BENCHMARK(BM_CopyCtorSparseInt)->Range(128, 4096);
+
+void BM_CopyCtorInt(benchmark::State& state) {
+ std::random_device rd;
+ std::mt19937 rng(rd());
+ IntTable t;
+ std::uniform_int_distribution<uint64_t> dist(0, ~uint64_t{});
+
+ size_t size = state.range(0);
+ while (t.size() < size) {
+ t.emplace(dist(rng));
+ }
+
+ for (auto i : state) {
IntTable t2 = t;
benchmark::DoNotOptimize(t2);
}
}
-BENCHMARK(BM_CopyCtor)->Range(128, 4096);
+BENCHMARK(BM_CopyCtorInt)->Range(128, 4096);
+
+void BM_CopyCtorString(benchmark::State& state) {
+ std::random_device rd;
+ std::mt19937 rng(rd());
+ StringTable t;
+ std::uniform_int_distribution<uint64_t> dist(0, ~uint64_t{});
+
+ size_t size = state.range(0);
+ while (t.size() < size) {
+ t.emplace(std::to_string(dist(rng)), std::to_string(dist(rng)));
+ }
+
+ for (auto i : state) {
+ StringTable t2 = t;
+ benchmark::DoNotOptimize(t2);
+ }
+}
+BENCHMARK(BM_CopyCtorString)->Range(128, 4096);
void BM_CopyAssign(benchmark::State& state) {
std::random_device rd;