Chris@1622
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@1622
|
2
|
Chris@1622
|
3 /*
|
Chris@1622
|
4 Sonic Visualiser
|
Chris@1622
|
5 An audio file viewer and annotation editor.
|
Chris@1622
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@1622
|
7
|
Chris@1622
|
8 This program is free software; you can redistribute it and/or
|
Chris@1622
|
9 modify it under the terms of the GNU General Public License as
|
Chris@1622
|
10 published by the Free Software Foundation; either version 2 of the
|
Chris@1622
|
11 License, or (at your option) any later version. See the file
|
Chris@1622
|
12 COPYING included with this distribution for more information.
|
Chris@1622
|
13 */
|
Chris@1622
|
14
|
Chris@1622
|
15 #ifndef STRESS_EVENT_SERIES_H
|
Chris@1622
|
16 #define STRESS_EVENT_SERIES_H
|
Chris@1622
|
17
|
Chris@1622
|
18 #include "../EventSeries.h"
|
Chris@1622
|
19
|
Chris@1622
|
20 #include <QObject>
|
Chris@1622
|
21 #include <QtTest>
|
Chris@1622
|
22
|
Chris@1622
|
23 #include <iostream>
|
Chris@1622
|
24
|
Chris@1622
|
25 using namespace std;
|
Chris@1622
|
26
|
Chris@1622
|
27 class StressEventSeries : public QObject
|
Chris@1622
|
28 {
|
Chris@1622
|
29 Q_OBJECT
|
Chris@1622
|
30
|
Chris@1622
|
31 private:
|
Chris@1622
|
32 void report(int n, QString sort, clock_t start, clock_t end) {
|
Chris@1622
|
33 QString message = QString("Time for %1 %2 events = ").arg(n).arg(sort);
|
Chris@1622
|
34 cerr << " " << message;
|
Chris@1622
|
35 for (int i = 0; i < 34 - message.size(); ++i) cerr << " ";
|
Chris@1622
|
36 cerr << double(end - start) * 1000.0 / double(CLOCKS_PER_SEC)
|
Chris@1622
|
37 << "ms" << endl;
|
Chris@1622
|
38 }
|
Chris@1622
|
39
|
Chris@1622
|
40 void short_n(int n) {
|
Chris@1622
|
41 clock_t start = clock();
|
Chris@1631
|
42 std::set<Event> ee;
|
Chris@1622
|
43 EventSeries s;
|
Chris@1622
|
44 for (int i = 0; i < n; ++i) {
|
Chris@1622
|
45 float value = float(rand()) / float(RAND_MAX);
|
Chris@1622
|
46 Event e(rand(), value, 1000, QString("event %1").arg(i));
|
Chris@1631
|
47 ee.insert(e);
|
Chris@1631
|
48 }
|
Chris@1631
|
49 for (const Event &e: ee) {
|
Chris@1622
|
50 s.add(e);
|
Chris@1622
|
51 }
|
Chris@1622
|
52 QCOMPARE(s.count(), n);
|
Chris@1622
|
53 clock_t end = clock();
|
Chris@1622
|
54 report(n, "short", start, end);
|
Chris@1622
|
55 }
|
Chris@1622
|
56
|
Chris@1622
|
57 void longish_n(int n) {
|
Chris@1622
|
58 clock_t start = clock();
|
Chris@1631
|
59 std::set<Event> ee;
|
Chris@1622
|
60 EventSeries s;
|
Chris@1622
|
61 for (int i = 0; i < n; ++i) {
|
Chris@1622
|
62 float value = float(rand()) / float(RAND_MAX);
|
Chris@1622
|
63 Event e(rand(), value, rand() / 1000, QString("event %1").arg(i));
|
Chris@1631
|
64 ee.insert(e);
|
Chris@1631
|
65 }
|
Chris@1631
|
66 for (const Event &e: ee) {
|
Chris@1622
|
67 s.add(e);
|
Chris@1622
|
68 }
|
Chris@1622
|
69 QCOMPARE(s.count(), n);
|
Chris@1622
|
70 clock_t end = clock();
|
Chris@1622
|
71 report(n, "longish", start, end);
|
Chris@1622
|
72 }
|
Chris@1622
|
73
|
Chris@1622
|
74 private slots:
|
Chris@1622
|
75 void short_3() { short_n(1000); }
|
Chris@1622
|
76 void short_4() { short_n(10000); }
|
Chris@1622
|
77 void short_5() { short_n(100000); }
|
Chris@1622
|
78 void short_6() { short_n(1000000); }
|
Chris@1622
|
79 void longish_3() { longish_n(1000); }
|
Chris@1622
|
80 void longish_4() { longish_n(10000); }
|
Chris@1622
|
81 void longish_5() { longish_n(100000); }
|
Chris@1622
|
82 };
|
Chris@1622
|
83
|
Chris@1622
|
84 #endif
|