# HG changeset patch # User Chris Cannam # Date 1552298008 0 # Node ID 172bd3374adfa4fe944f897e24eedbdd3a9b4398 # Parent cf5196881e3eeddb87d652ba875d4e2dc2459a66 Add (disabled by default) stress test for EventSeries diff -r cf5196881e3e -r 172bd3374adf base/test/StressEventSeries.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/base/test/StressEventSeries.h Mon Mar 11 09:53:28 2019 +0000 @@ -0,0 +1,92 @@ +/* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */ + +/* + Sonic Visualiser + An audio file viewer and annotation editor. + Centre for Digital Music, Queen Mary, University of London. + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License as + published by the Free Software Foundation; either version 2 of the + License, or (at your option) any later version. See the file + COPYING included with this distribution for more information. +*/ + +#ifndef STRESS_EVENT_SERIES_H +#define STRESS_EVENT_SERIES_H + +#include "../EventSeries.h" + +#include +#include + +#include + +using namespace std; + +class StressEventSeries : public QObject +{ + Q_OBJECT + +private: + void report(int n, QString sort, clock_t start, clock_t end) { + QString message = QString("Time for %1 %2 events = ").arg(n).arg(sort); + cerr << " " << message; + for (int i = 0; i < 34 - message.size(); ++i) cerr << " "; + cerr << double(end - start) * 1000.0 / double(CLOCKS_PER_SEC) + << "ms" << endl; + } + + void short_n(int n) { + clock_t start = clock(); + EventSeries s; + for (int i = 0; i < n; ++i) { + float value = float(rand()) / float(RAND_MAX); + Event e(rand(), value, 1000, QString("event %1").arg(i)); + s.add(e); + } + QCOMPARE(s.count(), n); + clock_t end = clock(); + report(n, "short", start, end); + } + + void longish_n(int n) { + clock_t start = clock(); + EventSeries s; + for (int i = 0; i < n; ++i) { + float value = float(rand()) / float(RAND_MAX); + Event e(rand(), value, rand() / 1000, QString("event %1").arg(i)); + s.add(e); + } + QCOMPARE(s.count(), n); + clock_t end = clock(); + report(n, "longish", start, end); + } + +private slots: + void short_3() { short_n(1000); } + void short_4() { short_n(10000); } + void short_5() { short_n(100000); } + void short_6() { short_n(1000000); } + void longish_3() { longish_n(1000); } + void longish_4() { longish_n(10000); } + void longish_5() { longish_n(100000); } + + /* cf5196881e3e+ + + Time for 1000 short events = 1.169ms + Time for 10000 short events = 20.566ms + Time for 100000 short events = 279.242ms + Time for 1000000 short events = 3925.06ms + Time for 1000 longish events = 1.938ms + Time for 10000 longish events = 72.209ms + Time for 100000 longish events = 6469.26ms + +Totals: 9 passed, 0 failed, 0 skipped, 0 blacklisted, 12785ms + +13.40user 0.37system 0:13.84elapsed 99%CPU (0avgtext+0avgdata 1052000maxresident)k +0inputs+40outputs (0major+260249minor)pagefaults 0swaps + */ +}; + +#endif diff -r cf5196881e3e -r 172bd3374adf base/test/files.pri --- a/base/test/files.pri Fri Mar 08 13:37:08 2019 +0000 +++ b/base/test/files.pri Mon Mar 11 09:53:28 2019 +0000 @@ -8,7 +8,8 @@ TestRangeMapper.h \ TestScaleTickIntervals.h \ TestStringBits.h \ - TestVampRealTime.h + TestVampRealTime.h \ + StressEventSeries.h TEST_SOURCES += \ svcore-base-test.cpp diff -r cf5196881e3e -r 172bd3374adf base/test/svcore-base-test.cpp --- a/base/test/svcore-base-test.cpp Fri Mar 08 13:37:08 2019 +0000 +++ b/base/test/svcore-base-test.cpp Mon Mar 11 09:53:28 2019 +0000 @@ -21,6 +21,7 @@ #include "TestColumnOp.h" #include "TestMovingMedian.h" #include "TestEventSeries.h" +#include "StressEventSeries.h" #include "system/Init.h" @@ -90,7 +91,14 @@ if (QTest::qExec(&t, argc, argv) == 0) ++good; else ++bad; } - +/* + { + StressEventSeries t; + if (QTest::qExec(&t, argc, argv) == 0) ++good; + else ++bad; + } +*/ + if (bad > 0) { SVCERR << "\n********* " << bad << " test suite(s) failed!\n" << endl; return 1;