blob: 6f4908b04f792c54f6b1b1aef367f54d66f088a1 (
plain)
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
// Copyright 2009-2021 The Mumble Developers. All rights reserved.
// Use of this source code is governed by a BSD-style license
// that can be found in the LICENSE file at the root of the
// Mumble source tree or at <https://www.mumble.info/LICENSE>.
#include <QtCore>
#include "Timer.h"
#define ITER 100000
typedef QPair< quint64, int > tr;
template< class T > class SpeedTest {
public:
QList< T > list;
SpeedTest() {}
void add(T v) { list << v; }
tr testres(T v) {
int val = 0;
Timer t;
t.restart();
for (int i = 0; i < ITER; i++) {
if (list.contains(v))
val++;
}
return tr(t.elapsed(), val);
}
};
int main(int argc, char **argv) {
QCoreApplication a(argc, argv);
QSet< int > set;
SpeedTest< QVariant > stv;
SpeedTest< int > sti;
SpeedTest< QList< QVariant > > stl;
SpeedTest< QVariant > stvl;
for (int i = 0; i < 300; i++) {
set.insert(i);
QVariant v = i;
QList< QVariant > ql;
ql << v;
QVariant vl = QVariant(ql);
stv.add(v);
sti.add(i);
stl.add(ql);
stvl.add(vl);
}
int i = 397;
QVariant v = i;
QList< QVariant > ql;
ql << v;
QVariant vl = QVariant(ql);
Timer tt;
tr t;
int val = 0;
tt.restart();
for (int i = 0; i < ITER; i++)
if (set.contains(i))
val++;
t.first = tt.elapsed();
t.second = val;
qWarning("set: %llu", t.first);
t = sti.testres(i);
qWarning("int: %llu", t.first / ITER);
t = stv.testres(v);
qWarning("var: %llu", t.first / ITER);
t = stl.testres(ql);
qWarning("lst: %llu", t.first / ITER);
t = stvl.testres(vl);
qWarning("vls: %llu", t.first / ITER);
}
#include "Hash.moc"
|