10 #include <benchmark/benchmark.h>
26 template <
typename K,
typename V>
33 std::vector<int> indices(
count);
34 std::iota(indices.begin(), indices.end(), 0);
35 std::shuffle(indices.begin(), indices.end(),
36 std::default_random_engine(0));
39 for (
int i = 0; i <
count; ++i) {
40 int v = indices[i] %
slots;
66 hashmap_warmup.Insert(keys, values, buf_indices, masks);
68 for (
auto _ : state) {
77 hashmap.Insert(keys, values, buf_indices, masks);
82 int64_t s = hashmap.Size();
85 "Error returning hashmap size, expected {}, but got {}.",
105 Tensor buf_indices, masks;
106 hashmap_warmup.Insert(keys, values, buf_indices, masks);
108 for (
auto _ : state) {
112 Tensor buf_indices, masks;
113 hashmap.Insert(keys, values, buf_indices, masks);
116 state.ResumeTiming();
118 hashmap.Erase(keys, masks);
123 int64_t s = hashmap.Size();
126 "Error returning hashmap size, expected {}, but got {}.", 0,
129 state.ResumeTiming();
135 int duplicate_factor,
146 Tensor buf_indices, masks;
148 hashmap.Insert(keys, values, buf_indices, masks);
150 for (
auto _ : state) {
151 hashmap.Find(keys, buf_indices, masks);
158 int duplicate_factor,
169 Tensor buf_indices, masks;
170 hashmap_warmup.Insert(keys, values, buf_indices, masks);
172 for (
auto _ : state) {
176 Tensor buf_indices, masks;
178 hashmap.Insert(keys, values, buf_indices, masks);
180 int64_t s = hashmap.Size();
183 "Error returning hashmap size, expected {}, but got {}.",
188 state.ResumeTiming();
198 "Error returning hashmap size, expected {}, but got {}.", 0,
201 state.ResumeTiming();
207 int duplicate_factor,
218 Tensor buf_indices, masks;
219 hashmap_warmup.Insert(keys, values, buf_indices, masks);
221 for (
auto _ : state) {
225 Tensor buf_indices, masks;
227 hashmap.Insert(keys, values, buf_indices, masks);
229 int64_t s = hashmap.Size();
232 "Error returning hashmap size, expected {}, but got {}.",
237 state.ResumeTiming();
239 hashmap.Reserve(2 * capacity);
247 "Error returning hashmap size, expected {}, but got {}.",
250 state.ResumeTiming();
259 return x_ == other.
x_ &&
y_ == other.
y_ &&
z_ == other.
z_;
268 int duplicate_factor,
274 std::vector<int> keys_Int3;
275 keys_Int3.assign(
reinterpret_cast<int*
>(data.
keys_.data()),
276 reinterpret_cast<int*
>(data.
keys_.data()) + 3 * capacity);
282 Tensor buf_indices, masks;
283 hashmap_warmup.Insert(keys, values, buf_indices, masks);
285 for (
auto _ : state) {
289 Tensor buf_indices, masks;
292 state.ResumeTiming();
294 hashmap.Insert(keys, values, buf_indices, masks);
299 int64_t s = hashmap.Size();
302 "Error returning hashmap size, expected {}, but got {}.",
305 state.ResumeTiming();
311 int duplicate_factor,
317 std::vector<int> keys_Int3;
318 keys_Int3.assign(
reinterpret_cast<int*
>(data.
keys_.data()),
319 reinterpret_cast<int*
>(data.
keys_.data()) + 3 * capacity);
325 Tensor buf_indices, masks;
326 hashmap_warmup.Insert(keys, values, buf_indices, masks);
328 for (
auto _ : state) {
332 Tensor buf_indices, masks;
333 hashmap.Insert(keys, values, buf_indices, masks);
336 state.ResumeTiming();
338 hashmap.Erase(keys, masks);
343 int64_t s = hashmap.Size();
346 "Error returning hashmap size, expected {}, but got {}.", 0,
349 state.ResumeTiming();
355 int duplicate_factor,
361 std::vector<int> keys_Int3;
362 keys_Int3.assign(
reinterpret_cast<int*
>(data.
keys_.data()),
363 reinterpret_cast<int*
>(data.
keys_.data()) + 3 * capacity);
369 Tensor buf_indices, masks;
370 hashmap.Insert(keys, values, buf_indices, masks);
372 for (
auto _ : state) {
373 hashmap.Find(keys, buf_indices, masks);
380 int duplicate_factor,
386 std::vector<int> keys_Int3;
387 keys_Int3.assign(
reinterpret_cast<int*
>(data.
keys_.data()),
388 reinterpret_cast<int*
>(data.
keys_.data()) + 3 * capacity);
394 Tensor buf_indices, masks;
395 hashmap_warmup.Insert(keys, values, buf_indices, masks);
397 for (
auto _ : state) {
401 Tensor buf_indices, masks;
403 hashmap.Insert(keys, values, buf_indices, masks);
405 int64_t s = hashmap.Size();
408 "Error returning hashmap size, expected {}, but got {}.",
413 state.ResumeTiming();
423 "Error returning hashmap size, expected {}, but got {}.", 0,
426 state.ResumeTiming();
432 int duplicate_factor,
438 std::vector<int> keys_Int3;
439 keys_Int3.assign(
reinterpret_cast<int*
>(data.
keys_.data()),
440 reinterpret_cast<int*
>(data.
keys_.data()) + 3 * capacity);
446 Tensor buf_indices, masks;
447 hashmap_warmup.Insert(keys, values, buf_indices, masks);
449 for (
auto _ : state) {
453 Tensor buf_indices, masks;
455 hashmap.Insert(keys, values, buf_indices, masks);
457 int64_t s = hashmap.Size();
460 "Error returning hashmap size, expected {}, but got {}.",
465 state.ResumeTiming();
467 hashmap.Reserve(2 * capacity);
475 "Error returning hashmap size, expected {}, but got {}.",
478 state.ResumeTiming();
484 #define ENUM_BM_CAPACITY(FN, FACTOR, DEVICE, BACKEND) \
485 BENCHMARK_CAPTURE(FN, BACKEND##_100_##FACTOR, 100, FACTOR, DEVICE, \
487 ->Unit(benchmark::kMillisecond); \
488 BENCHMARK_CAPTURE(FN, BACKEND##_1000_##FACTOR, 1000, FACTOR, DEVICE, \
490 ->Unit(benchmark::kMillisecond); \
491 BENCHMARK_CAPTURE(FN, BACKEND##_10000_##FACTOR, 10000, FACTOR, DEVICE, \
493 ->Unit(benchmark::kMillisecond); \
494 BENCHMARK_CAPTURE(FN, BACKEND##_100000_##FACTOR, 100000, FACTOR, DEVICE, \
496 ->Unit(benchmark::kMillisecond); \
497 BENCHMARK_CAPTURE(FN, BACKEND##_1000000_##FACTOR, 1000000, FACTOR, DEVICE, \
499 ->Unit(benchmark::kMillisecond);
501 #define ENUM_BM_FACTOR(FN, DEVICE, BACKEND) \
502 ENUM_BM_CAPACITY(FN, 1, DEVICE, BACKEND) \
503 ENUM_BM_CAPACITY(FN, 2, DEVICE, BACKEND) \
504 ENUM_BM_CAPACITY(FN, 4, DEVICE, BACKEND) \
505 ENUM_BM_CAPACITY(FN, 8, DEVICE, BACKEND) \
506 ENUM_BM_CAPACITY(FN, 16, DEVICE, BACKEND) \
507 ENUM_BM_CAPACITY(FN, 32, DEVICE, BACKEND)
509 #ifdef BUILD_CUDA_MODULE
510 #define ENUM_BM_BACKEND(FN) \
511 ENUM_BM_FACTOR(FN, Device("CPU:0"), HashBackendType::TBB) \
512 ENUM_BM_FACTOR(FN, Device("CUDA:0"), HashBackendType::Slab) \
513 ENUM_BM_FACTOR(FN, Device("CUDA:0"), HashBackendType::StdGPU)
515 #define ENUM_BM_BACKEND(FN) \
516 ENUM_BM_FACTOR(FN, Device("CPU:0"), HashBackendType::TBB)
#define ENUM_BM_BACKEND(FN)
HashData(int count, int slots)
bool operator==(const Int3 &other) const
void HashClearInt(benchmark::State &state, int capacity, int duplicate_factor, const Device &device, const HashBackendType &backend)
void HashReserveInt3(benchmark::State &state, int capacity, int duplicate_factor, const Device &device, const HashBackendType &backend)
void HashFindInt(benchmark::State &state, int capacity, int duplicate_factor, const Device &device, const HashBackendType &backend)
void HashClearInt3(benchmark::State &state, int capacity, int duplicate_factor, const Device &device, const HashBackendType &backend)
void HashInsertInt3(benchmark::State &state, int capacity, int duplicate_factor, const Device &device, const HashBackendType &backend)
void HashReserveInt(benchmark::State &state, int capacity, int duplicate_factor, const Device &device, const HashBackendType &backend)
void HashEraseInt(benchmark::State &state, int capacity, int duplicate_factor, const Device &device, const HashBackendType &backend)
void HashFindInt3(benchmark::State &state, int capacity, int duplicate_factor, const Device &device, const HashBackendType &backend)
void HashInsertInt(benchmark::State &state, int capacity, int duplicate_factor, const Device &device, const HashBackendType &backend)
void HashEraseInt3(benchmark::State &state, int capacity, int duplicate_factor, const Device &device, const HashBackendType &backend)
Generic file read and write utility for python interface.