-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.cpp
More file actions
72 lines (59 loc) · 1.1 KB
/
test.cpp
File metadata and controls
72 lines (59 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// +
#include "test.h"
#include "qmap_wrapper.h"
#include <qtest.h>
namespace
{
template<class T = QMap<QString, int>>
T generateMapStringKey()
{
T map;
for (size_t ii = 0; ii < 1'000'000; ++ii) { map[std::to_string(ii).c_str()] = ii; }
return map;
}
}
void Test::qmap_values()
{
auto map = generateMapStringKey();
QBENCHMARK
{
int sum = 0;
for (const auto &value : map) { sum += value; }
}
}
void Test::qmap_keys()
{
auto map = generateMapStringKey();
QBENCHMARK
{
int sum = 0;
for (const auto &key : map.keys()) { sum += map[key]; }
}
}
void Test::qmap_tostdmap()
{
auto map = generateMapStringKey();
QBENCHMARK
{
int sum = 0;
for (const auto &it : map.toStdMap()) { sum += it.second; }
}
}
void Test::qmap_iterator()
{
auto map = generateMapStringKey();
QBENCHMARK
{
int sum = 0;
for (auto it = map.begin(); it != map.end(); ++it) { sum += it.value(); }
}
}
void Test::qmap_wrapper()
{
auto map = generateMapStringKey();
QBENCHMARK
{
int sum = 0;
for (const auto it : ::qmap_wrapper{map}) { sum += it.second; }
}
}