diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/CMakeLists.txt | 2 | ||||
-rw-r--r-- | tests/databasepopulationandfacadequerybenchmark.cpp | 32 | ||||
-rw-r--r-- | tests/dummyresourcewritebenchmark.cpp | 35 | ||||
-rw-r--r-- | tests/utils.cpp | 38 | ||||
-rw-r--r-- | tests/utils.h | 7 |
5 files changed, 48 insertions, 66 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6a757ca..e957f22 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt | |||
@@ -13,7 +13,7 @@ add_definitions(-DTHREADTESTDATAPATH="${CMAKE_CURRENT_SOURCE_DIR}/threaddata") | |||
13 | 13 | ||
14 | find_package(KF5 COMPONENTS REQUIRED Mime) | 14 | find_package(KF5 COMPONENTS REQUIRED Mime) |
15 | 15 | ||
16 | add_library(sink_test SHARED testimplementations.cpp getrssusage.cpp mailtest.cpp mailsynctest.cpp mailthreadtest.cpp) | 16 | add_library(sink_test SHARED testimplementations.cpp getrssusage.cpp mailtest.cpp mailsynctest.cpp mailthreadtest.cpp utils.cpp) |
17 | target_link_libraries(sink_test | 17 | target_link_libraries(sink_test |
18 | sink | 18 | sink |
19 | libhawd | 19 | libhawd |
diff --git a/tests/databasepopulationandfacadequerybenchmark.cpp b/tests/databasepopulationandfacadequerybenchmark.cpp index 58b6561..f965dd6 100644 --- a/tests/databasepopulationandfacadequerybenchmark.cpp +++ b/tests/databasepopulationandfacadequerybenchmark.cpp | |||
@@ -16,10 +16,10 @@ | |||
16 | #include "hawd/formatter.h" | 16 | #include "hawd/formatter.h" |
17 | 17 | ||
18 | #include <iostream> | 18 | #include <iostream> |
19 | #include <math.h> | ||
20 | 19 | ||
21 | #include "event_generated.h" | 20 | #include "event_generated.h" |
22 | #include "getrssusage.h" | 21 | #include "getrssusage.h" |
22 | #include "utils.h" | ||
23 | 23 | ||
24 | /** | 24 | /** |
25 | * Benchmark read performance of the facade implementation. | 25 | * Benchmark read performance of the facade implementation. |
@@ -188,36 +188,6 @@ private slots: | |||
188 | // testLoad(10000); | 188 | // testLoad(10000); |
189 | // } | 189 | // } |
190 | 190 | ||
191 | static double variance(const QList<double> &values) | ||
192 | { | ||
193 | double mean = 0; | ||
194 | for (auto value : values) { | ||
195 | mean += value; | ||
196 | } | ||
197 | mean = mean / static_cast<double>(values.size()); | ||
198 | double variance = 0; | ||
199 | for (auto value : values) { | ||
200 | variance += pow(static_cast<double>(value) - mean, 2); | ||
201 | } | ||
202 | variance = variance / static_cast<double>(values.size() - 1); | ||
203 | return variance; | ||
204 | } | ||
205 | |||
206 | static double maxDifference(const QList<double> &values) | ||
207 | { | ||
208 | auto max = values.first(); | ||
209 | auto min = values.first(); | ||
210 | for (auto value : values) { | ||
211 | if (value > max) { | ||
212 | max = value; | ||
213 | } | ||
214 | if (value < min) { | ||
215 | min = value; | ||
216 | } | ||
217 | } | ||
218 | return max - min; | ||
219 | } | ||
220 | |||
221 | void ensureUsedMemoryRemainsStable() | 191 | void ensureUsedMemoryRemainsStable() |
222 | { | 192 | { |
223 | auto rssStandardDeviation = sqrt(variance(mRssGrowthPerEntity)); | 193 | auto rssStandardDeviation = sqrt(variance(mRssGrowthPerEntity)); |
diff --git a/tests/dummyresourcewritebenchmark.cpp b/tests/dummyresourcewritebenchmark.cpp index c350b1a..9815f96 100644 --- a/tests/dummyresourcewritebenchmark.cpp +++ b/tests/dummyresourcewritebenchmark.cpp | |||
@@ -24,40 +24,7 @@ | |||
24 | #include "createentity_generated.h" | 24 | #include "createentity_generated.h" |
25 | 25 | ||
26 | #include "getrssusage.h" | 26 | #include "getrssusage.h" |
27 | 27 | #include "utils.h" | |
28 | static double variance(const QList<double> &values) | ||
29 | { | ||
30 | //The variance of a single value is 0 | ||
31 | if (values.size() == 1) { | ||
32 | return 0; | ||
33 | } | ||
34 | double mean = 0; | ||
35 | for (auto value : values) { | ||
36 | mean += value; | ||
37 | } | ||
38 | mean = mean / static_cast<double>(values.size()); | ||
39 | double variance = 0; | ||
40 | for (auto value : values) { | ||
41 | variance += pow(static_cast<double>(value) - mean, 2); | ||
42 | } | ||
43 | variance = variance / static_cast<double>(values.size() - 1); | ||
44 | return variance; | ||
45 | } | ||
46 | |||
47 | static double maxDifference(const QList<double> &values) | ||
48 | { | ||
49 | auto max = values.first(); | ||
50 | auto min = values.first(); | ||
51 | for (auto value : values) { | ||
52 | if (value > max) { | ||
53 | max = value; | ||
54 | } | ||
55 | if (value < min) { | ||
56 | min = value; | ||
57 | } | ||
58 | } | ||
59 | return max - min; | ||
60 | } | ||
61 | 28 | ||
62 | static QByteArray createEntityBuffer(int &bufferSize) | 29 | static QByteArray createEntityBuffer(int &bufferSize) |
63 | { | 30 | { |
diff --git a/tests/utils.cpp b/tests/utils.cpp new file mode 100644 index 0000000..dfaab17 --- /dev/null +++ b/tests/utils.cpp | |||
@@ -0,0 +1,38 @@ | |||
1 | #include "utils.h" | ||
2 | |||
3 | #include <QList> | ||
4 | #include <math.h> | ||
5 | |||
6 | double variance(const QList<double> &values) | ||
7 | { | ||
8 | //The variance of a single value is 0 | ||
9 | if (values.size() == 1) { | ||
10 | return 0; | ||
11 | } | ||
12 | double mean = 0; | ||
13 | for (auto value : values) { | ||
14 | mean += value; | ||
15 | } | ||
16 | mean = mean / static_cast<double>(values.size()); | ||
17 | double variance = 0; | ||
18 | for (auto value : values) { | ||
19 | variance += pow(static_cast<double>(value) - mean, 2); | ||
20 | } | ||
21 | variance = variance / static_cast<double>(values.size() - 1); | ||
22 | return variance; | ||
23 | } | ||
24 | |||
25 | double maxDifference(const QList<double> &values) | ||
26 | { | ||
27 | auto max = values.first(); | ||
28 | auto min = values.first(); | ||
29 | for (auto value : values) { | ||
30 | if (value > max) { | ||
31 | max = value; | ||
32 | } | ||
33 | if (value < min) { | ||
34 | min = value; | ||
35 | } | ||
36 | } | ||
37 | return max - min; | ||
38 | } | ||
diff --git a/tests/utils.h b/tests/utils.h new file mode 100644 index 0000000..45c1409 --- /dev/null +++ b/tests/utils.h | |||
@@ -0,0 +1,7 @@ | |||
1 | #pragma once | ||
2 | |||
3 | #include <QList> | ||
4 | |||
5 | double variance(const QList<double> &values); | ||
6 | double maxDifference(const QList<double> &values); | ||
7 | |||