1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
/*
* Copyright 2012 Canonical Ltd.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Author: Florian Boucault <florian.boucault@canonical.com>
*/
#include <QtCore/QDir>
#include <QtCore/QUrl>
#include <QtQml/QQmlComponent>
#include <QtQml/QQmlEngine>
#include <QtTest/QtTest>
#include <LomiriToolkit/lomiritoolkitglobal.h>
class tst_components_benchmark: public QObject
{
Q_OBJECT
private Q_SLOTS:
void benchmark_creation_components_data() {
QTest::addColumn<QString>("fileName");
QDir dir;
dir.setPath(QString("%1/%2.%3").arg(LOMIRI_COMPONENT_PATH).arg(MAJOR_VERSION(LATEST_UITK_VERSION)).arg(MINOR_VERSION(LATEST_UITK_VERSION)));
QVERIFY2(dir.exists(), qPrintable(dir.absolutePath()));
QStringList nameFilters;
nameFilters << "*.qml";
dir.setNameFilters(nameFilters);
dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
dir.setSorting(QDir::Size | QDir::Reversed);
QFileInfoList list = dir.entryInfoList();
QVERIFY2(list.size(), qPrintable(dir.absolutePath()));
for (int i = 0; i < list.size(); ++i) {
QFileInfo fileInfo = list.at(i);
QTest::newRow(fileInfo.fileName().toLatin1()) << fileInfo.fileName();
}
}
void benchmark_creation_components() {
QFETCH(QString, fileName);
QQmlComponent component(&engine, fileName);
QObject *obj = component.create();
obj->deleteLater();
QBENCHMARK {
QObject *obj = component.create();
obj->deleteLater();
}
}
void benchmark_creation_listitems_data() {
QTest::addColumn<QString>("fileName");
QDir dir;
dir.setPath(QString("%1/ListItems/%2.%3").arg(LOMIRI_COMPONENT_PATH).arg(MAJOR_VERSION(LATEST_UITK_VERSION)).arg(MINOR_VERSION(LATEST_UITK_VERSION)));
QVERIFY2(dir.exists(), qPrintable(dir.absolutePath()));
QStringList nameFilters;
nameFilters << "*.qml";
dir.setNameFilters(nameFilters);
dir.setFilter(QDir::Files | QDir::Hidden | QDir::NoSymLinks);
dir.setSorting(QDir::Size | QDir::Reversed);
QFileInfoList list = dir.entryInfoList();
QVERIFY2(list.size(), qPrintable(dir.absolutePath()));
for (int i = 0; i < list.size(); ++i) {
QFileInfo fileInfo = list.at(i);
QTest::newRow(fileInfo.fileName().toLatin1()) << fileInfo.fileName();
}
}
void benchmark_creation_listitems() {
QFETCH(QString, fileName);
QQmlComponent component(&engine, fileName);
QObject *obj = component.create();
obj->deleteLater();
QBENCHMARK {
QObject *obj = component.create();
obj->deleteLater();
}
}
private:
QQmlEngine engine;
};
QTEST_MAIN(tst_components_benchmark)
#include "tst_components_benchmark.moc"
|