//----------------------------------------------------------------------------- // map.cc: ./map --benchmark_time_unit=ms //----------------------------------------------------------------------------- #include #include // #include // C++23 #include #include #include #include #include //----------------------------------------------------------------------------- const std::size_t N = 10'000; std::random_device device; std::default_random_engine engine(device()); std::uniform_int_distribution distribution; auto rng = [] { return distribution(engine); }; //----------------------------------------------------------------------------- template void test(benchmark::State &state) { C container; for (auto _: state) for (std::size_t r = 0; r < N; ++r) { auto i = rng(); auto s = std::to_string(i); switch (i % 6) { case 0: container[i] = s; break; case 1: try { container.at(i) = s; } catch(...) {}; break; case 2: container.insert({i, s}); break; case 3: std::ignore = container.find(i); break; case 4: container.erase(i); break; case 5: std::ignore = container.count(i); break; } } } //----------------------------------------------------------------------------- BENCHMARK(test>); BENCHMARK(test>); BENCHMARK(test>); BENCHMARK(test>); BENCHMARK_MAIN(); //-----------------------------------------------------------------------------