Chris@1622: /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ Chris@1622: Chris@1622: /* Chris@1622: Sonic Visualiser Chris@1622: An audio file viewer and annotation editor. Chris@1622: Centre for Digital Music, Queen Mary, University of London. Chris@1622: Chris@1622: This program is free software; you can redistribute it and/or Chris@1622: modify it under the terms of the GNU General Public License as Chris@1622: published by the Free Software Foundation; either version 2 of the Chris@1622: License, or (at your option) any later version. See the file Chris@1622: COPYING included with this distribution for more information. Chris@1622: */ Chris@1622: Chris@1622: #ifndef STRESS_EVENT_SERIES_H Chris@1622: #define STRESS_EVENT_SERIES_H Chris@1622: Chris@1622: #include "../EventSeries.h" Chris@1622: Chris@1622: #include Chris@1622: #include Chris@1622: Chris@1622: #include Chris@1622: Chris@1622: using namespace std; Chris@1622: Chris@1622: class StressEventSeries : public QObject Chris@1622: { Chris@1622: Q_OBJECT Chris@1622: Chris@1622: private: Chris@1622: void report(int n, QString sort, clock_t start, clock_t end) { Chris@1622: QString message = QString("Time for %1 %2 events = ").arg(n).arg(sort); Chris@1622: cerr << " " << message; Chris@1622: for (int i = 0; i < 34 - message.size(); ++i) cerr << " "; Chris@1622: cerr << double(end - start) * 1000.0 / double(CLOCKS_PER_SEC) Chris@1622: << "ms" << endl; Chris@1622: } Chris@1622: Chris@1622: void short_n(int n) { Chris@1622: clock_t start = clock(); Chris@1622: EventSeries s; Chris@1622: for (int i = 0; i < n; ++i) { Chris@1622: float value = float(rand()) / float(RAND_MAX); Chris@1622: Event e(rand(), value, 1000, QString("event %1").arg(i)); Chris@1622: s.add(e); Chris@1622: } Chris@1622: QCOMPARE(s.count(), n); Chris@1622: clock_t end = clock(); Chris@1622: report(n, "short", start, end); Chris@1622: } Chris@1622: Chris@1622: void longish_n(int n) { Chris@1622: clock_t start = clock(); Chris@1622: EventSeries s; Chris@1622: for (int i = 0; i < n; ++i) { Chris@1622: float value = float(rand()) / float(RAND_MAX); Chris@1622: Event e(rand(), value, rand() / 1000, QString("event %1").arg(i)); Chris@1622: s.add(e); Chris@1622: } Chris@1622: QCOMPARE(s.count(), n); Chris@1622: clock_t end = clock(); Chris@1622: report(n, "longish", start, end); Chris@1622: } Chris@1622: Chris@1622: private slots: Chris@1622: void short_3() { short_n(1000); } Chris@1622: void short_4() { short_n(10000); } Chris@1622: void short_5() { short_n(100000); } Chris@1622: void short_6() { short_n(1000000); } Chris@1622: void longish_3() { longish_n(1000); } Chris@1622: void longish_4() { longish_n(10000); } Chris@1622: void longish_5() { longish_n(100000); } Chris@1622: Chris@1625: /* Chris@1625: Chris@1625: cf5196881e3e: Chris@1622: Chris@1622: Time for 1000 short events = 1.169ms Chris@1622: Time for 10000 short events = 20.566ms Chris@1622: Time for 100000 short events = 279.242ms Chris@1622: Time for 1000000 short events = 3925.06ms Chris@1622: Time for 1000 longish events = 1.938ms Chris@1622: Time for 10000 longish events = 72.209ms Chris@1622: Time for 100000 longish events = 6469.26ms Chris@1622: Chris@1622: Totals: 9 passed, 0 failed, 0 skipped, 0 blacklisted, 12785ms Chris@1622: Chris@1622: 13.40user 0.37system 0:13.84elapsed 99%CPU (0avgtext+0avgdata 1052000maxresident)k Chris@1622: 0inputs+40outputs (0major+260249minor)pagefaults 0swaps Chris@1625: Chris@1625: Chris@1625: dcd510bd89db: Chris@1625: Chris@1625: Time for 1000 short events = 1.824ms Chris@1625: Time for 10000 short events = 19.203ms Chris@1625: Time for 100000 short events = 270.631ms Chris@1625: Time for 1000000 short events = 4425.2ms Chris@1625: Time for 1000 longish events = 2.395ms Chris@1625: Time for 10000 longish events = 83.623ms Chris@1625: Time for 100000 longish events = 5958.28ms Chris@1625: Chris@1625: Totals: 9 passed, 0 failed, 0 skipped, 0 blacklisted, 13116ms Chris@1625: Chris@1625: 13.64user 0.26system 0:13.98elapsed 99%CPU (0avgtext+0avgdata 948104maxresident)k Chris@1625: 0inputs+40outputs (0major+234387minor)pagefaults 0swaps Chris@1625: Chris@1627: 895186c43fce: Chris@1627: Chris@1627: Time for 1000 short events = 1.706ms Chris@1627: Time for 10000 short events = 23.192ms Chris@1627: Time for 100000 short events = 310.605ms Chris@1627: Time for 1000000 short events = 4675.7ms Chris@1627: Time for 1000 longish events = 2.186ms Chris@1627: Time for 10000 longish events = 760.659ms Chris@1627: Time for 100000 longish events = 1335.57ms Chris@1627: Chris@1627: Totals: 9 passed, 0 failed, 0 skipped, 0 blacklisted, 7804ms Chris@1627: Chris@1627: 7.97user 0.29system 0:08.31elapsed 99%CPU (0avgtext+0avgdata 706388maxresident)k Chris@1627: 0inputs+40outputs (0major+182225minor)pagefaults 0swaps Chris@1627: Chris@1622: */ Chris@1622: }; Chris@1622: Chris@1622: #endif