16 #include <type_traits>
21 #include "absl/base/attributes.h"
22 #include "absl/container/flat_hash_set.h"
23 #include "absl/hash/hash.h"
24 #include "absl/random/random.h"
25 #include "absl/strings/cord.h"
26 #include "absl/strings/cord_test_helpers.h"
27 #include "absl/strings/string_view.h"
28 #include "benchmark/benchmark.h"
34 template <
template <
typename>
class H,
typename T>
82 template <
typename FuncType>
95 const size_t orig_size =
size;
96 std::vector<std::string> chunks;
97 size_t chunk_size = std::max<size_t>(1,
size / 10);
98 while (
size > chunk_size) {
107 assert(
result.size() == orig_size);
111 template <
typename T>
114 for (
size_t v = 0;
v <
count; ++
v) {
123 template <
typename T>
126 for (
size_t v = 0;
v <
count; ++
v) {
132 template <
typename H>
134 return H::combine(H::combine_unordered(
std::move(h), fus.
values.begin(),
140 template <
typename T>
143 for (
size_t v = 0;
v <
count; ++
v) {
151 #define MAKE_BENCHMARK(hash, name, ...) \
153 void BM_##hash##_##name(benchmark::State& state) { \
154 RunBenchmark<hash>(state, __VA_ARGS__); \
156 BENCHMARK(BM_##hash##_##name); \
158 size_t Codegen##hash##name(const decltype(__VA_ARGS__)& arg); \
159 size_t Codegen##hash##name(const decltype(__VA_ARGS__)& arg) { \
160 return hash<decltype(__VA_ARGS__)>{}(arg); \
162 bool absl_hash_test_odr_use##hash##name = \
163 ODRUseFunction(&Codegen##hash##name);
172 std::tuple<int32_t, bool, int64_t>{});
219 std::pair<int32_t, int32_t>{});
221 std::pair<int64_t, int64_t>{});
223 std::tuple<int32_t, bool, int64_t>{});
231 std::vector<double>(10, 1.1));
233 std::vector<double>(100, 1.1));
235 std::vector<double>(1000, 1.1));
237 FlatHashSet<int64_t>(10));
239 FlatHashSet<int64_t>(100));
241 FlatHashSet<int64_t>(1000));
243 FlatHashSet<double>(10));
245 FlatHashSet<double>(100));
247 FlatHashSet<double>(1000));
267 static constexpr
size_t kEntropySize = 16 << 10;
268 static char entropy[kEntropySize + 1024];
271 static_assert(
sizeof(entropy) %
sizeof(
uint64_t) == 0,
"");
272 for (
int i = 0;
i !=
sizeof(entropy);
i +=
sizeof(
uint64_t)) {
273 auto rand = absl::Uniform<uint64_t>(
gen);
283 static_assert(kEntropySize +
sizeof(
T) <
sizeof(entropy),
"");
287 memcpy(&
v, &entropy[
i % kEntropySize],
sizeof(
T));
294 static_assert(kEntropySize +
N <
sizeof(entropy),
"");
300 size_t s = (
i % (
N - 1)) + 1;
301 return {&entropy[
i % kEntropySize], s};
305 #define MAKE_LATENCY_BENCHMARK(hash, name, ...) \
307 void BM_latency_##hash##_##name(benchmark::State& state) { \
309 hash<decltype(r.Get(0))> h; \
310 size_t i = 871401241; \
311 for (auto _ : state) { \
312 benchmark::DoNotOptimize(i = h(r.Get(i))); \
315 BENCHMARK(BM_latency_##hash##_##name); \