Mercurial > hg > svcore
comparison base/test/StressEventSeries.h @ 1622:172bd3374adf single-point
Add (disabled by default) stress test for EventSeries
author | Chris Cannam |
---|---|
date | Mon, 11 Mar 2019 09:53:28 +0000 |
parents | |
children | 7dbb2a7b592e |
comparison
equal
deleted
inserted
replaced
1621:cf5196881e3e | 1622:172bd3374adf |
---|---|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ | |
2 | |
3 /* | |
4 Sonic Visualiser | |
5 An audio file viewer and annotation editor. | |
6 Centre for Digital Music, Queen Mary, University of London. | |
7 | |
8 This program is free software; you can redistribute it and/or | |
9 modify it under the terms of the GNU General Public License as | |
10 published by the Free Software Foundation; either version 2 of the | |
11 License, or (at your option) any later version. See the file | |
12 COPYING included with this distribution for more information. | |
13 */ | |
14 | |
15 #ifndef STRESS_EVENT_SERIES_H | |
16 #define STRESS_EVENT_SERIES_H | |
17 | |
18 #include "../EventSeries.h" | |
19 | |
20 #include <QObject> | |
21 #include <QtTest> | |
22 | |
23 #include <iostream> | |
24 | |
25 using namespace std; | |
26 | |
27 class StressEventSeries : public QObject | |
28 { | |
29 Q_OBJECT | |
30 | |
31 private: | |
32 void report(int n, QString sort, clock_t start, clock_t end) { | |
33 QString message = QString("Time for %1 %2 events = ").arg(n).arg(sort); | |
34 cerr << " " << message; | |
35 for (int i = 0; i < 34 - message.size(); ++i) cerr << " "; | |
36 cerr << double(end - start) * 1000.0 / double(CLOCKS_PER_SEC) | |
37 << "ms" << endl; | |
38 } | |
39 | |
40 void short_n(int n) { | |
41 clock_t start = clock(); | |
42 EventSeries s; | |
43 for (int i = 0; i < n; ++i) { | |
44 float value = float(rand()) / float(RAND_MAX); | |
45 Event e(rand(), value, 1000, QString("event %1").arg(i)); | |
46 s.add(e); | |
47 } | |
48 QCOMPARE(s.count(), n); | |
49 clock_t end = clock(); | |
50 report(n, "short", start, end); | |
51 } | |
52 | |
53 void longish_n(int n) { | |
54 clock_t start = clock(); | |
55 EventSeries s; | |
56 for (int i = 0; i < n; ++i) { | |
57 float value = float(rand()) / float(RAND_MAX); | |
58 Event e(rand(), value, rand() / 1000, QString("event %1").arg(i)); | |
59 s.add(e); | |
60 } | |
61 QCOMPARE(s.count(), n); | |
62 clock_t end = clock(); | |
63 report(n, "longish", start, end); | |
64 } | |
65 | |
66 private slots: | |
67 void short_3() { short_n(1000); } | |
68 void short_4() { short_n(10000); } | |
69 void short_5() { short_n(100000); } | |
70 void short_6() { short_n(1000000); } | |
71 void longish_3() { longish_n(1000); } | |
72 void longish_4() { longish_n(10000); } | |
73 void longish_5() { longish_n(100000); } | |
74 | |
75 /* cf5196881e3e+ | |
76 | |
77 Time for 1000 short events = 1.169ms | |
78 Time for 10000 short events = 20.566ms | |
79 Time for 100000 short events = 279.242ms | |
80 Time for 1000000 short events = 3925.06ms | |
81 Time for 1000 longish events = 1.938ms | |
82 Time for 10000 longish events = 72.209ms | |
83 Time for 100000 longish events = 6469.26ms | |
84 | |
85 Totals: 9 passed, 0 failed, 0 skipped, 0 blacklisted, 12785ms | |
86 | |
87 13.40user 0.37system 0:13.84elapsed 99%CPU (0avgtext+0avgdata 1052000maxresident)k | |
88 0inputs+40outputs (0major+260249minor)pagefaults 0swaps | |
89 */ | |
90 }; | |
91 | |
92 #endif |