SPH
Map.cpp
Go to the documentation of this file.
1 #include "bench/Session.h"
3 #include <map>
4 
5 
6 using namespace Sph;
7 
8 template <typename TMap>
9 static void benchmarkMap(TMap& map, Benchmark::Context& context) {
10  std::hash<int> hash;
11  constexpr int num = 10000;
12  while (context.running()) {
13  Size sum = 0;
14  for (Size i = 0; i < num; ++i) {
15  Benchmark::doNotOptimize(sum += map[hash(i) % map.size()]);
16  }
18  }
19 }
20 
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) });
25  }
26  benchmarkMap(map, context);
27 }
28 
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));
33  }
34  benchmarkMap(map, context);
35 }
36 
37 
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) });
42  }
43  benchmarkMap(map, context);
44 }
45 
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));
50  }
51  benchmarkMap(map, context);
52 }
53 
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) });
58  }
59  benchmarkMap(map, context);
60 }
61 
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));
66  }
67  benchmarkMap(map, context);
68 }
69 
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) });
74  }
75  benchmarkMap(map, context);
76 }
77 
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));
82  }
83  benchmarkMap(map, context);
84 }
Key-value associative container implemented as a sorted array.
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
BENCHMARK("std::map 10", "[flatmap]", Benchmark::Context &context)
Definition: Map.cpp:21
Benchmark.
INLINE T && doNotOptimize(T &&value)
Definition: Session.h:180
INLINE void clobberMemory()
Definition: Session.h:190
Container of key-value pairs.
Definition: FlatMap.h:19
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.
Definition: FlatMap.h:65
constexpr Size sum()
Definition: Multipole.h:31
Definition: MemoryPool.h:5