Commit 800c04f6 by Abseil Team Committed by Copybara-Service

Add sparse and string copy constructor benchmarks for hash table.

PiperOrigin-RevId: 475601161
Change-Id: I3f67a1597ddfa6de60f19fe4b38d44fbc5630bd8
parent d4607b3f
...@@ -15,8 +15,8 @@ ...@@ -15,8 +15,8 @@
#include <array> #include <array>
#include <cmath> #include <cmath>
#include <numeric> #include <numeric>
#include <utility>
#include <random> #include <random>
#include <utility>
#include <vector> #include <vector>
#include "absl/base/internal/raw_logging.h" #include "absl/base/internal/raw_logging.h"
...@@ -258,22 +258,60 @@ BENCHMARK(BM_Iteration) ...@@ -258,22 +258,60 @@ BENCHMARK(BM_Iteration)
->ArgPair(100, 1) ->ArgPair(100, 1)
->ArgPair(1000, 10); ->ArgPair(1000, 10);
void BM_CopyCtor(benchmark::State& state) { void BM_CopyCtorSparseInt(benchmark::State& state) {
std::random_device rd; std::random_device rd;
std::mt19937 rng(rd()); std::mt19937 rng(rd());
IntTable t; IntTable t;
std::uniform_int_distribution<uint64_t> dist(0, ~uint64_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)); 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; IntTable t2 = t;
benchmark::DoNotOptimize(t2); 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) { void BM_CopyAssign(benchmark::State& state) {
std::random_device rd; std::random_device rd;
......
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