From 7377e8f950d550d8823914588c35e541c48ab3ce Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Fri, 5 Aug 2016 11:41:52 +0200 Subject: tst_librarymetrics_performance: Use QBENCHMARK macro instead of rolling our own This means we now respect -callgrind to show instruction counts (for instance). If benchmarks don't already throw out outliers and perform averaging, we should roll those features into testlib, not replace it. Change-Id: I21a3c4b41ec80a49b5b61bfe957f1165ac865010 Reviewed-by: Simon Hausmann --- .../tst_librarymetrics_performance.cpp | 147 ++------------------- 1 file changed, 14 insertions(+), 133 deletions(-) (limited to 'tests/benchmarks/qml') diff --git a/tests/benchmarks/qml/librarymetrics_performance/tst_librarymetrics_performance.cpp b/tests/benchmarks/qml/librarymetrics_performance/tst_librarymetrics_performance.cpp index ad72ebc6f0..4b69975dac 100644 --- a/tests/benchmarks/qml/librarymetrics_performance/tst_librarymetrics_performance.cpp +++ b/tests/benchmarks/qml/librarymetrics_performance/tst_librarymetrics_performance.cpp @@ -41,9 +41,6 @@ // for the standard set of elements, properties and expressions which // are provided in the QtDeclarative library (QtQml and QtQuick). -#define AVERAGE_OVER_N 10 -#define IGNORE_N_OUTLIERS 2 - class ModuleApi : public QObject { Q_OBJECT @@ -219,123 +216,37 @@ void tst_librarymetrics_performance::compilation() } } - QList nResults; - - // generate AVERAGE_OVER_N results - for (int i = 0; i < AVERAGE_OVER_N; ++i) { + QBENCHMARK { cleanState(&e); - { - QElapsedTimer et; - et.start(); - QQmlComponent c(e, this); - c.loadUrl(qmlfile); // just compile. - qint64 etime = et.nsecsElapsed(); - nResults.append(etime); - } - } - - // sort the list - qSort(nResults); - - // remove IGNORE_N_OUTLIERS*2 from ONLY the worst end (remove gc interference) - for (int i = 0; i < IGNORE_N_OUTLIERS; ++i) { - if (!nResults.isEmpty()) nResults.removeLast(); - if (!nResults.isEmpty()) nResults.removeLast(); + QQmlComponent c(e, this); + c.loadUrl(qmlfile); // just compile. } - - // now generate an average - qint64 totaltime = 0; - if (nResults.size() == 0) nResults.append(9999); - for (int i = 0; i < nResults.size(); ++i) - totaltime += nResults.at(i); - double average = ((double)totaltime) / nResults.count(); - - // and return it as the result - QTest::setBenchmarkResult(average, QTest::WalltimeNanoseconds); - QTest::setBenchmarkResult(average, QTest::WalltimeNanoseconds); // twice to workaround bug in QTestLib } void tst_librarymetrics_performance::instantiation_cached() { QFETCH(QUrl, qmlfile); - cleanState(&e); - QList nResults; - // generate AVERAGE_OVER_N results - for (int i = 0; i < AVERAGE_OVER_N; ++i) { - QElapsedTimer et; - et.start(); + QBENCHMARK { QQmlComponent c(e, this); c.loadUrl(qmlfile); // just compile. QObject *o = c.create(); - qint64 etime = et.nsecsElapsed(); - nResults.append(etime); delete o; } - - // sort the list - qSort(nResults); - - // remove IGNORE_N_OUTLIERS*2 from ONLY the worst end (remove gc interference) - for (int i = 0; i < IGNORE_N_OUTLIERS; ++i) { - if (!nResults.isEmpty()) nResults.removeLast(); - if (!nResults.isEmpty()) nResults.removeLast(); - } - - // now generate an average - qint64 totaltime = 0; - if (nResults.size() == 0) nResults.append(9999); - for (int i = 0; i < nResults.size(); ++i) - totaltime += nResults.at(i); - double average = ((double)totaltime) / nResults.count(); - - // and return it as the result - QTest::setBenchmarkResult(average, QTest::WalltimeNanoseconds); - QTest::setBenchmarkResult(average, QTest::WalltimeNanoseconds); // twice to workaround bug in QTestLib } void tst_librarymetrics_performance::instantiation() { QFETCH(QUrl, qmlfile); - cleanState(&e); - QList nResults; - - // generate AVERAGE_OVER_N results - for (int i = 0; i < AVERAGE_OVER_N; ++i) { + QBENCHMARK { cleanState(&e); - { - QElapsedTimer et; - et.start(); - QQmlComponent c(e, this); - c.loadUrl(qmlfile); // just compile. - QObject *o = c.create(); - qint64 etime = et.nsecsElapsed(); - nResults.append(etime); - delete o; - } - } - - // sort the list - qSort(nResults); - - // remove IGNORE_N_OUTLIERS*2 from ONLY the worst end (remove gc interference) - for (int i = 0; i < IGNORE_N_OUTLIERS; ++i) { - if (!nResults.isEmpty()) nResults.removeLast(); - if (!nResults.isEmpty()) nResults.removeLast(); + QQmlComponent c(e, this); + c.loadUrl(qmlfile); // just compile. + QObject *o = c.create(); + delete o; } - - // now generate an average - qint64 totaltime = 0; - if (nResults.size() == 0) nResults.append(9999); - for (int i = 0; i < nResults.size(); ++i) - totaltime += nResults.at(i); - double average = ((double)totaltime) / nResults.count(); - - // and return it as the result - QTest::setBenchmarkResult(average, QTest::WalltimeNanoseconds); - QTest::setBenchmarkResult(average, QTest::WalltimeNanoseconds); // twice to workaround bug in QTestLib } void tst_librarymetrics_performance::positioners_data() @@ -356,43 +267,13 @@ void tst_librarymetrics_performance::positioners() { QFETCH(QUrl, qmlfile); - cleanState(&e); - QList nResults; - - // generate AVERAGE_OVER_N results - for (int i = 0; i < AVERAGE_OVER_N; ++i) { + QBENCHMARK { cleanState(&e); - { - QElapsedTimer et; - et.start(); - QQmlComponent c(e, this); - c.loadUrl(qmlfile); // just compile. - QObject *o = c.create(); - qint64 etime = et.nsecsElapsed(); - nResults.append(etime); - delete o; - } - } - - // sort the list - qSort(nResults); - - // remove IGNORE_N_OUTLIERS*2 from ONLY the worst end (remove gc interference) - for (int i = 0; i < IGNORE_N_OUTLIERS; ++i) { - if (!nResults.isEmpty()) nResults.removeLast(); - if (!nResults.isEmpty()) nResults.removeLast(); + QQmlComponent c(e, this); + c.loadUrl(qmlfile); // just compile. + QObject *o = c.create(); + delete o; } - - // now generate an average - qint64 totaltime = 0; - if (nResults.size() == 0) nResults.append(9999); - for (int i = 0; i < nResults.size(); ++i) - totaltime += nResults.at(i); - double average = ((double)totaltime) / nResults.count(); - - // and return it as the result - QTest::setBenchmarkResult(average, QTest::WalltimeNanoseconds); - QTest::setBenchmarkResult(average, QTest::WalltimeNanoseconds); // twice to workaround bug in QTestLib } QTEST_MAIN(tst_librarymetrics_performance) -- cgit v1.2.3