#include #include #include #include #include // for max #include // for size_t #include // for move #include // for vector template void fill(counter& counts, Map& map, ankerl::nanobench::Rng& rng) { auto n = rng.bounded(20); for (size_t i = 0; i < n; ++i) { auto a = rng.bounded(20); auto b = rng.bounded(20); map.try_emplace({a, counts}, b, counts); } } TEST_CASE_MAP("vectormap", counter::obj, counter::obj) { auto counts = counter(); INFO(counts); auto rng = ankerl::nanobench::Rng(32154); { counts("begin"); std::vector maps; // copies for (size_t i = 0; i < 10; ++i) { map_t m; fill(counts, m, rng); maps.push_back(m); } counts("copies"); // move for (size_t i = 0; i < 10; ++i) { map_t m; fill(counts, m, rng); maps.push_back(std::move(m)); } counts("move"); // emplace for (size_t i = 0; i < 10; ++i) { maps.emplace_back(); fill(counts, maps.back(), rng); } counts("emplace"); } counts("dtor"); REQUIRE(counts.dtor() == counts.ctor() + counts.static_default_ctor + counts.copy_ctor() + counts.default_ctor() + counts.move_ctor()); }