From 561b9ce09d8ad3e5c8e9c622ab70034975cfe48f Mon Sep 17 00:00:00 2001 From: J-P Nurmi Date: Sun, 15 Nov 2015 16:11:58 +0100 Subject: Add material style to benchmarks Change-Id: I2b8d09f8dcd1380af849f3263bf2ea7599681190 Reviewed-by: Mitch Curtis --- tests/benchmarks/creationtime/tst_creationtime.cpp | 72 ++++++++++++++++------ tests/benchmarks/objectcount/tst_objectcount.cpp | 50 ++++++++++++--- 2 files changed, 95 insertions(+), 27 deletions(-) diff --git a/tests/benchmarks/creationtime/tst_creationtime.cpp b/tests/benchmarks/creationtime/tst_creationtime.cpp index 7ce6947b..2a61b0ea 100644 --- a/tests/benchmarks/creationtime/tst_creationtime.cpp +++ b/tests/benchmarks/creationtime/tst_creationtime.cpp @@ -47,6 +47,9 @@ private slots: void controls(); void controls_data(); + void material(); + void material_data(); + void universal(); void universal_data(); @@ -62,21 +65,44 @@ void tst_CreationTime::init() engine.clearComponentCache(); } -static void addTestRows(const QString &path) +static void addTestRows(QQmlEngine *engine, const QString &targetPath, const QStringList &skiplist = QStringList()) { - QFileInfoList entries = QDir(path).entryInfoList(QStringList("*.qml"), QDir::Files); - foreach (const QFileInfo &entry, entries) - QTest::newRow(qPrintable(entry.baseName())) << QUrl::fromLocalFile(entry.absoluteFilePath()); + // We cannot use QQmlComponent to load QML files directly from the source tree. + // For styles that use internal QML types (eg. material/Ripple.qml), the source + // dir would be added as an "implicit" import path overriding the actual import + // path (qtbase/qml/Qt/labs/controls/material). => The QML engine fails to load + // the style C++ plugin from the implicit import path (the source dir). + // + // Therefore we only use the source tree for finding out the set of QML files that + // a particular style implements, and then we locate the respective QML files in + // the engine's import path. This way we can use QQmlComponent to load each QML file + // for benchmarking. + + QFileInfoList entries = QDir(QQC2_IMPORT_PATH + targetPath).entryInfoList(QStringList("*.qml"), QDir::Files); + foreach (const QFileInfo &entry, entries) { + QString name = entry.baseName(); + if (!skiplist.contains(name)) { + foreach (const QString &importPath, engine->importPathList()) { + QString filePath = QDir(importPath + "/Qt/labs/" + targetPath).absoluteFilePath(entry.fileName()); + if (QFile::exists(filePath)) { + QTest::newRow(qPrintable(name)) << QUrl::fromLocalFile(filePath); + break; + } + } + } + } } -static void doBenchmark(QQmlComponent *component) +static void doBenchmark(QQmlEngine *engine, const QUrl &url) { + QQmlComponent component(engine); + component.loadUrl(url); + QObjectList objects; objects.reserve(4096); QBENCHMARK { - QObject *object = component->create(); - if (!object) - qFatal("%s", qPrintable(component->errorString())); + QObject *object = component.create(); + QVERIFY2(object, qPrintable(component.errorString())); objects += object; } qDeleteAll(objects); @@ -85,43 +111,49 @@ static void doBenchmark(QQmlComponent *component) void tst_CreationTime::controls() { QFETCH(QUrl, url); - QQmlComponent component(&engine); - component.loadUrl(url); - doBenchmark(&component); + doBenchmark(&engine, url); } void tst_CreationTime::controls_data() { QTest::addColumn("url"); - addTestRows(QQC2_IMPORT_PATH "/controls"); + addTestRows(&engine, "/controls"); +} + +void tst_CreationTime::material() +{ + QFETCH(QUrl, url); + doBenchmark(&engine, url); +} + +void tst_CreationTime::material_data() +{ + QTest::addColumn("url"); + addTestRows(&engine, "/controls/material", QStringList() << "Ripple" << "SliderHandle"); } void tst_CreationTime::universal() { QFETCH(QUrl, url); - QQmlComponent component(&engine); - component.loadUrl(url); - doBenchmark(&component); + doBenchmark(&engine, url); } void tst_CreationTime::universal_data() { QTest::addColumn("url"); - addTestRows(QQC2_IMPORT_PATH "/controls/universal"); + addTestRows(&engine, "/controls/universal"); } void tst_CreationTime::calendar() { QFETCH(QUrl, url); - QQmlComponent component(&engine); - component.loadUrl(url); - doBenchmark(&component); + doBenchmark(&engine, url); } void tst_CreationTime::calendar_data() { QTest::addColumn("url"); - addTestRows(QQC2_IMPORT_PATH "/calendar"); + addTestRows(&engine, "/calendar"); } QTEST_MAIN(tst_CreationTime) diff --git a/tests/benchmarks/objectcount/tst_objectcount.cpp b/tests/benchmarks/objectcount/tst_objectcount.cpp index f2998708..59956588 100644 --- a/tests/benchmarks/objectcount/tst_objectcount.cpp +++ b/tests/benchmarks/objectcount/tst_objectcount.cpp @@ -69,6 +69,9 @@ private slots: void controls(); void controls_data(); + void material(); + void material_data(); + void universal(); void universal_data(); @@ -102,11 +105,32 @@ static void printItems(const QList &items) } } -static void addTestRows(const QString &path) +static void addTestRows(QQmlEngine *engine, const QString &targetPath, const QStringList &skiplist = QStringList()) { - QFileInfoList entries = QDir(path).entryInfoList(QStringList("*.qml"), QDir::Files); - foreach (const QFileInfo &entry, entries) - QTest::newRow(qPrintable(entry.baseName())) << QUrl::fromLocalFile(entry.absoluteFilePath()); + // We cannot use QQmlComponent to load QML files directly from the source tree. + // For styles that use internal QML types (eg. material/Ripple.qml), the source + // dir would be added as an "implicit" import path overriding the actual import + // path (qtbase/qml/Qt/labs/controls/material). => The QML engine fails to load + // the style C++ plugin from the implicit import path (the source dir). + // + // Therefore we only use the source tree for finding out the set of QML files that + // a particular style implements, and then we locate the respective QML files in + // the engine's import path. This way we can use QQmlComponent to load each QML file + // for benchmarking. + + QFileInfoList entries = QDir(QQC2_IMPORT_PATH + targetPath).entryInfoList(QStringList("*.qml"), QDir::Files); + foreach (const QFileInfo &entry, entries) { + QString name = entry.baseName(); + if (!skiplist.contains(name)) { + foreach (const QString &importPath, engine->importPathList()) { + QString filePath = QDir(importPath + "/Qt/labs/" + targetPath).absoluteFilePath(entry.fileName()); + if (QFile::exists(filePath)) { + QTest::newRow(qPrintable(name)) << QUrl::fromLocalFile(filePath); + break; + } + } + } + } } static void doBenchmark(QQmlEngine *engine, const QUrl &url) @@ -137,7 +161,7 @@ void tst_ObjectCount::calendar() void tst_ObjectCount::calendar_data() { QTest::addColumn("url"); - addTestRows(QQC2_IMPORT_PATH "/calendar"); + addTestRows(&engine, "/calendar"); } void tst_ObjectCount::legacy() @@ -216,7 +240,19 @@ void tst_ObjectCount::controls() void tst_ObjectCount::controls_data() { QTest::addColumn("url"); - addTestRows(QQC2_IMPORT_PATH "/controls"); + addTestRows(&engine, "/controls"); +} + +void tst_ObjectCount::material() +{ + QFETCH(QUrl, url); + doBenchmark(&engine, url); +} + +void tst_ObjectCount::material_data() +{ + QTest::addColumn("url"); + addTestRows(&engine, "/controls/material", QStringList() << "Ripple" << "SliderHandle"); } void tst_ObjectCount::universal() @@ -228,7 +264,7 @@ void tst_ObjectCount::universal() void tst_ObjectCount::universal_data() { QTest::addColumn("url"); - addTestRows(QQC2_IMPORT_PATH "/controls/universal"); + addTestRows(&engine, "/controls/universal"); } QTEST_MAIN(tst_ObjectCount) -- cgit v1.2.3