8 template <
typename TMap>
9 static void benchmarkMap(TMap& map, Benchmark::Context& context) {
11 constexpr
int num = 10000;
12 while (context.running()) {
14 for (
Size i = 0; i < num; ++i) {
21 BENCHMARK(
"std::map 10",
"[flatmap]", Benchmark::Context& context) {
22 std::map<int, std::size_t> map;
23 for (
Size i = 0; i < 10; ++i) {
24 map.insert({ i, std::hash<int>{}(i) });
26 benchmarkMap(map, context);
29 BENCHMARK(
"Sph::Map 10",
"[flatmap]", Benchmark::Context& context) {
31 for (
Size i = 0; i < 10; ++i) {
32 map.
insert(i, std::hash<int>{}(i));
34 benchmarkMap(map, context);
38 BENCHMARK(
"std::map 100",
"[flatmap]", Benchmark::Context& context) {
39 std::map<int, std::size_t> map;
40 for (
Size i = 0; i < 100; ++i) {
41 map.insert({ i, std::hash<int>{}(i) });
43 benchmarkMap(map, context);
46 BENCHMARK(
"Sph::Map 100",
"[flatmap]", Benchmark::Context& context) {
48 for (
Size i = 0; i < 100; ++i) {
49 map.
insert(i, std::hash<int>{}(i));
51 benchmarkMap(map, context);
54 BENCHMARK(
"std::map 1000",
"[flatmap]", Benchmark::Context& context) {
55 std::map<int, std::size_t> map;
56 for (
Size i = 0; i < 1000; ++i) {
57 map.insert({ i, std::hash<int>{}(i) });
59 benchmarkMap(map, context);
62 BENCHMARK(
"Sph::Map 1000",
"[flatmap]", Benchmark::Context& context) {
64 for (
Size i = 0; i < 1000; ++i) {
65 map.
insert(i, std::hash<int>{}(i));
67 benchmarkMap(map, context);
70 BENCHMARK(
"std::map 10000",
"[flatmap]", Benchmark::Context& context) {
71 std::map<int, std::size_t> map;
72 for (
Size i = 0; i < 10000; ++i) {
73 map.insert({ i, std::hash<int>{}(i) });
75 benchmarkMap(map, context);
78 BENCHMARK(
"Sph::Map 10000",
"[flatmap]", Benchmark::Context& context) {
80 for (
Size i = 0; i < 10000; ++i) {
81 map.
insert(i, std::hash<int>{}(i));
83 benchmarkMap(map, context);
Key-value associative container implemented as a sorted array.
uint32_t Size
Integral type used to index arrays (by default).
BENCHMARK("std::map 10", "[flatmap]", Benchmark::Context &context)
INLINE T && doNotOptimize(T &&value)
INLINE void clobberMemory()
Container of key-value pairs.
INLINE TValue & insert(const TKey &key, const TValue &value)
Adds a new element into the map or sets new value of element with the same key.