diff --git a/src/benchmarks/Insert.cpp b/src/benchmarks/Insert.cpp index 8300927..8530e50 100644 --- a/src/benchmarks/Insert.cpp +++ b/src/benchmarks/Insert.cpp @@ -42,3 +42,70 @@ BENCHMARK(InsertHugeInt) { } bench.endMeasure(0, 0); } + +std::array counts = { + 200, 2000, 2000, 20000, 200000, 2000000, 20000000 +}; + +std::array results = { + 20000000, 19999999, 19999998, 19999957, 19999529, 19995213, 19953523 +}; + +BENCHMARK(CreateInsert) { + sfc64 rng(213); + for (size_t i = 0; i < counts.size(); ++i) { + size_t count = counts[i]; + size_t repeats = counts.back() / count; + size_t res = 0; + + bench.beginMeasure(("creating and inserting " + std::to_string(count) + + " ints " + std::to_string(repeats) + + " times").c_str()); + + for (size_t j = 0; j < repeats; ++j) { + + using M = Map; +#ifdef USE_POOL_ALLOCATOR + Resource resource; + M map{0, M::hasher{}, M::key_equal{}, &resource}; +#else + M map; +#endif + + for (size_t n = 0; n < count; ++n) + map[static_cast(rng())]; + res += map.size(); + } + bench.endMeasure(results[i], res); + } +} + +BENCHMARK(ClearInsert) { + sfc64 rng(213); + for (size_t i = 0; i < counts.size(); ++i) { + size_t count = counts[i]; + size_t repeats = counts.back() / count; + size_t res = 0; + + using M = Map; +#ifdef USE_POOL_ALLOCATOR + Resource resource; + M map{0, M::hasher{}, M::key_equal{}, &resource}; +#else + M map; +#endif + + bench.beginMeasure(("inserting and clearing " + std::to_string(count) + + " ints " + std::to_string(repeats) + + " times").c_str()); + + for (size_t j = 0; j < repeats; ++j) { + for (size_t n = 0; n < count; ++n) + map[static_cast(rng())]; + res += map.size(); + map.clear(); + } + bench.endMeasure(results[i], res); + } +} +