16 #include <type_traits>
21 #include "absl/base/attributes.h"
22 #include "absl/hash/hash.h"
23 #include "absl/random/random.h"
24 #include "absl/strings/cord.h"
25 #include "absl/strings/cord_test_helpers.h"
26 #include "absl/strings/string_view.h"
27 #include "benchmark/benchmark.h"
33 template <
template <
typename>
class H,
typename T>
81 template <
typename FuncType>
94 const size_t orig_size =
size;
95 std::vector<std::string> chunks;
96 size_t chunk_size = std::max<size_t>(1,
size / 10);
97 while (
size > chunk_size) {
106 assert(
result.size() == orig_size);
112 #define MAKE_BENCHMARK(hash, name, ...) \
114 void BM_##hash##_##name(benchmark::State& state) { \
115 RunBenchmark<hash>(state, __VA_ARGS__); \
117 BENCHMARK(BM_##hash##_##name); \
119 size_t Codegen##hash##name(const decltype(__VA_ARGS__)& arg); \
120 size_t Codegen##hash##name(const decltype(__VA_ARGS__)& arg) { \
121 return hash<decltype(__VA_ARGS__)>{}(arg); \
123 bool absl_hash_test_odr_use##hash##name = \
124 ODRUseFunction(&Codegen##hash##name);
133 std::tuple<int32_t, bool, int64_t>{});
168 std::pair<int32_t, int32_t>{});
170 std::pair<int64_t, int64_t>{});
172 std::tuple<int32_t, bool, int64_t>{});
180 std::vector<double>(10, 1.1));
182 std::vector<double>(100, 1.1));
198 static constexpr
size_t kEntropySize = 16 << 10;
199 static char entropy[kEntropySize + 1024];
202 static_assert(
sizeof(entropy) %
sizeof(
uint64_t) == 0,
"");
203 for (
int i = 0;
i !=
sizeof(entropy);
i +=
sizeof(
uint64_t)) {
204 auto rand = absl::Uniform<uint64_t>(
gen);
214 static_assert(kEntropySize +
sizeof(
T) <
sizeof(entropy),
"");
218 memcpy(&
v, &entropy[
i % kEntropySize],
sizeof(
T));
225 static_assert(kEntropySize +
N <
sizeof(entropy),
"");
231 size_t s = (
i % (
N - 1)) + 1;
232 return {&entropy[
i % kEntropySize], s};
236 #define MAKE_LATENCY_BENCHMARK(hash, name, ...) \
238 void BM_latency_##hash##_##name(benchmark::State& state) { \
240 hash<decltype(r.Get(0))> h; \
241 size_t i = 871401241; \
242 for (auto _ : state) { \
243 benchmark::DoNotOptimize(i = h(r.Get(i))); \
246 BENCHMARK(BM_latency_##hash##_##name); \