diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2021-01-28 12:54:48 +0100 |
---|---|---|
committer | Maximilian Goldstein <max.goldstein@qt.io> | 2021-02-04 09:29:59 +0100 |
commit | 5164b36501cd039a2ddd1e3a5ebaf90f315e0382 (patch) | |
tree | 0d478a03844e63afbbc0468c2896260b20366628 | |
parent | e0c0fd5713c27b1bf9536213cee33494ac734f2d (diff) |
Import property benchmarks from private repo
Change-Id: If45bf9bfcfee127263a2c0e49cfa55e12f9a6d0f
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r-- | tests/benchmarks/qml/CMakeLists.txt | 1 | ||||
-rw-r--r-- | tests/benchmarks/qml/qproperty/CMakeLists.txt | 11 | ||||
-rw-r--r-- | tests/benchmarks/qml/qproperty/data/main.qml | 6 | ||||
-rw-r--r-- | tests/benchmarks/qml/qproperty/data/new.qml | 6 | ||||
-rw-r--r-- | tests/benchmarks/qml/qproperty/data/notified.qml | 6 | ||||
-rw-r--r-- | tests/benchmarks/qml/qproperty/data/old.qml | 6 | ||||
-rw-r--r-- | tests/benchmarks/qml/qproperty/main.cpp | 242 | ||||
-rw-r--r-- | tests/benchmarks/qml/qproperty/propertytester.h | 83 |
8 files changed, 361 insertions, 0 deletions
diff --git a/tests/benchmarks/qml/CMakeLists.txt b/tests/benchmarks/qml/CMakeLists.txt index e1ce51462f..ec1decf33c 100644 --- a/tests/benchmarks/qml/CMakeLists.txt +++ b/tests/benchmarks/qml/CMakeLists.txt @@ -11,6 +11,7 @@ add_subdirectory(librarymetrics_performance) add_subdirectory(script) add_subdirectory(js) add_subdirectory(creation) +add_subdirectory(qproperty) if(TARGET Qt::OpenGL) add_subdirectory(qquickwindow) endif() diff --git a/tests/benchmarks/qml/qproperty/CMakeLists.txt b/tests/benchmarks/qml/qproperty/CMakeLists.txt new file mode 100644 index 0000000000..51faa5d86c --- /dev/null +++ b/tests/benchmarks/qml/qproperty/CMakeLists.txt @@ -0,0 +1,11 @@ +qt_internal_add_benchmark(tst_bench_qproperty_qml + SOURCES + main.cpp + propertytester.h + DEFINES + SRCDIR=\\\"${CMAKE_CURRENT_SOURCE_DIR}\\\" + PUBLIC_LIBRARIES + Qt::Gui + Qt::Qml + Qt::Test +) diff --git a/tests/benchmarks/qml/qproperty/data/main.qml b/tests/benchmarks/qml/qproperty/data/main.qml new file mode 100644 index 0000000000..8cc4ba535b --- /dev/null +++ b/tests/benchmarks/qml/qproperty/data/main.qml @@ -0,0 +1,6 @@ +import Test 1 + +Test { + x: 0 + y: x +} diff --git a/tests/benchmarks/qml/qproperty/data/new.qml b/tests/benchmarks/qml/qproperty/data/new.qml new file mode 100644 index 0000000000..8cc4ba535b --- /dev/null +++ b/tests/benchmarks/qml/qproperty/data/new.qml @@ -0,0 +1,6 @@ +import Test 1 + +Test { + x: 0 + y: x +} diff --git a/tests/benchmarks/qml/qproperty/data/notified.qml b/tests/benchmarks/qml/qproperty/data/notified.qml new file mode 100644 index 0000000000..2e2fe31e60 --- /dev/null +++ b/tests/benchmarks/qml/qproperty/data/notified.qml @@ -0,0 +1,6 @@ +import Test 1 + +Test { + xNotified: 0 + yNotified: xNotified +} diff --git a/tests/benchmarks/qml/qproperty/data/old.qml b/tests/benchmarks/qml/qproperty/data/old.qml new file mode 100644 index 0000000000..618a196ef1 --- /dev/null +++ b/tests/benchmarks/qml/qproperty/data/old.qml @@ -0,0 +1,6 @@ +import Test 1 + +Test { + xOld: 0 + yOld: xOld +} diff --git a/tests/benchmarks/qml/qproperty/main.cpp b/tests/benchmarks/qml/qproperty/main.cpp new file mode 100644 index 0000000000..947933c586 --- /dev/null +++ b/tests/benchmarks/qml/qproperty/main.cpp @@ -0,0 +1,242 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QGuiApplication> +#include <QQmlEngine> +#include <QQmlComponent> +#include <QScopedPointer> +#include <qqml.h> +#include <QProperty> + +#include <qtest.h> + +#include "propertytester.h" + +class PropertyBenchmark : public QObject +{ + Q_OBJECT +public: + PropertyBenchmark(); + +private slots: + void oldStyleProperty(); + void oldStylePropertyReadOnce(); + void oldStylePropertyDirect(); + void oldStylePropertyDirectReadOnce(); + + void newStyleProperty(); + void newStylePropertyReadOnce(); + void newStylePropertyDirect(); + void newStylePropertyDirectReadOnce(); + + void notifyingProperty(); + void notifyingPropertyReadOnce(); + void notifyingPropertyDirect(); + void notifyingPropertyDirectReadOnce(); +private: + QScopedPointer<QQmlEngine> m_engine; +}; + +PropertyBenchmark::PropertyBenchmark() + : m_engine(new QQmlEngine) +{ + qmlRegisterType<PropertyTester>("Test", 1, 0, "Test"); +} + +inline QUrl TEST_FILE(const QString &filename) +{ + return QUrl::fromLocalFile(QLatin1String(SRCDIR) + QLatin1String("/data/") + filename); +} + +void PropertyBenchmark::oldStyleProperty() +{ + QQmlComponent component (m_engine.data(), QUrl(TEST_FILE("old.qml"))); + QScopedPointer item {(PropertyTester *) component.create()}; + QVERIFY(item); + QCOMPARE(item->property("yOld").toInt(), 0); + int i = 0; + QBENCHMARK { + item->setProperty("xOld", ++i); + if (item->property("yOld").toInt() != i) + QFAIL("boo"); + } +} + +void PropertyBenchmark::oldStylePropertyDirect() +{ + QQmlComponent component (m_engine.data(), QUrl(TEST_FILE("old.qml"))); + QScopedPointer item {(PropertyTester *) component.create()}; + QVERIFY(item); + QCOMPARE(item->yOld(), 0); + int i = 0; + QBENCHMARK { + item->setXOld(++i); + if (item->yOld() != i) + QFAIL("boo"); + } +} + +void PropertyBenchmark::oldStylePropertyReadOnce() +{ + QQmlComponent component (m_engine.data(), QUrl(TEST_FILE("old.qml"))); + QScopedPointer item {(PropertyTester *) component.create()}; + QVERIFY(item); + QCOMPARE(item->property("yOld").toInt(), 0); + int i = 0; + QBENCHMARK { + item->setProperty("xOld", ++i); + } + QCOMPARE(item->property("yOld").toInt(), i); +} + +void PropertyBenchmark::oldStylePropertyDirectReadOnce() +{ + QQmlComponent component (m_engine.data(), QUrl(TEST_FILE("old.qml"))); + QScopedPointer item {(PropertyTester *) component.create()}; + QVERIFY(item); + QCOMPARE(item->yOld(), 0); + int i = 0; + QBENCHMARK { + item->setXOld(++i); + } + + QCOMPARE(item->yOld(), i); +} + +void PropertyBenchmark::newStyleProperty() +{ + QQmlComponent component (m_engine.data(), QUrl(TEST_FILE("new.qml"))); + QScopedPointer item {(PropertyTester *) component.create()}; + QVERIFY(item); + QCOMPARE(item->property("y").toInt(), 0); + int i = 0; + QBENCHMARK { + item->setProperty("x", ++i); + if (item->property("y").toInt() != i) + QFAIL("boo"); + } +} + +void PropertyBenchmark::newStylePropertyDirect() +{ + QQmlComponent component (m_engine.data(), QUrl(TEST_FILE("new.qml"))); + QScopedPointer item {(PropertyTester *) component.create()}; + QVERIFY(item); + QCOMPARE(item->y.value(), 0); + int i = 0; + QBENCHMARK { + item->x = ++i; + if (item->y.value() != i) + QFAIL("boo"); + } +} + +void PropertyBenchmark::newStylePropertyReadOnce() +{ + QQmlComponent component (m_engine.data(), QUrl(TEST_FILE("new.qml"))); + QScopedPointer item {(PropertyTester *) component.create()}; + QVERIFY(item); + QCOMPARE(item->property("y").toInt(), 0); + int i = 0; + QBENCHMARK { + item->setProperty("x", ++i); + } + QCOMPARE(item->property("y").toInt(), i); +} + +void PropertyBenchmark::newStylePropertyDirectReadOnce() +{ + QQmlComponent component (m_engine.data(), QUrl(TEST_FILE("new.qml"))); + QScopedPointer item {(PropertyTester *) component.create()}; + QVERIFY(item); + QCOMPARE(item->y.value(), 0); + int i = 0; + QBENCHMARK { + item->x = ++i; + } + + QCOMPARE(item->y.value(), i); +} + +void PropertyBenchmark::notifyingProperty() +{ + QQmlComponent component (m_engine.data(), QUrl(TEST_FILE("notified.qml"))); + QScopedPointer item {(PropertyTester *) component.create()}; + QVERIFY(item); + QCOMPARE(item->property("yNotified").toInt(), 0); + int i = 0; + QBENCHMARK { + item->setProperty("xNotified", ++i); + if (item->property("yNotified").toInt() != i) + QFAIL("boo"); + } +} + +void PropertyBenchmark::notifyingPropertyDirect() +{ + QQmlComponent component (m_engine.data(), QUrl(TEST_FILE("notified.qml"))); + QScopedPointer item {(PropertyTester *) component.create()}; + QVERIFY(item); + QCOMPARE(item->yNotified.value(), 0); + int i = 0; + QBENCHMARK { + item->xNotified.setValue(++i); + if (item->yNotified.value() != i) + QFAIL("boo"); + } +} + +void PropertyBenchmark::notifyingPropertyReadOnce() +{ + QQmlComponent component (m_engine.data(), QUrl(TEST_FILE("notified.qml"))); + QScopedPointer item {(PropertyTester *) component.create()}; + QVERIFY(item); + QCOMPARE(item->property("yNotified").toInt(), 0); + int i = 0; + QBENCHMARK { + item->setProperty("xNotified", ++i); + } + QCOMPARE(item->property("yNotified").toInt(), i); +} + +void PropertyBenchmark::notifyingPropertyDirectReadOnce() +{ + QQmlComponent component (m_engine.data(), QUrl(TEST_FILE("notified.qml"))); + QScopedPointer item {(PropertyTester *) component.create()}; + QVERIFY(item); + QCOMPARE(item->yNotified.value(), 0); + int i = 0; + QBENCHMARK { + item->xNotified.setValue(++i); + } + + QCOMPARE(item->yNotified.value(), i); +} + +QTEST_MAIN(PropertyBenchmark) +#include "main.moc" diff --git a/tests/benchmarks/qml/qproperty/propertytester.h b/tests/benchmarks/qml/qproperty/propertytester.h new file mode 100644 index 0000000000..daf55f8396 --- /dev/null +++ b/tests/benchmarks/qml/qproperty/propertytester.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:GPL-EXCEPT$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3 as published by the Free Software +** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT +** included in the packaging of this file. Please review the following +** information to ensure the GNU General Public License requirements will +** be met: https://www.gnu.org/licenses/gpl-3.0.html. +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef PROPERTYTESTER_H +#define PROPERTYTESTER_H + +#include <QObject> +#include <QProperty> + +class PropertyTester : public QObject +{ + Q_OBJECT +signals: + void xOldChanged(); + void yOldChanged(); + void xNotifiedChanged(); + void yNotifiedChanged(); + +public: + PropertyTester() = default; + Q_PROPERTY(int xOld READ xOld WRITE setXOld NOTIFY xOldChanged) + Q_PROPERTY(int yOld READ yOld WRITE setYOld NOTIFY yOldChanged) + Q_PROPERTY(int x MEMBER x BINDABLE xBindable) + Q_PROPERTY(int y MEMBER y BINDABLE yBindable) + Q_PROPERTY(int xNotified MEMBER xNotified NOTIFY xNotifiedChanged BINDABLE xNotifiedBindable) + Q_PROPERTY(int yNotified MEMBER yNotified NOTIFY yNotifiedChanged BINDABLE yNotifiedBindable) + void setXOld(int i) { + if (m_xOld != i) { + m_xOld = i; + emit xOldChanged(); + } + } + void setYOld(int i) { + if (m_yOld != i) { + m_yOld = i; + emit yOldChanged(); + } + } + int xOld() { return m_xOld; } + int yOld() { return m_yOld; } + QProperty<int> x; + QProperty<int> y; + + QBindable<int> xBindable() { return QBindable<int>(&x); } + QBindable<int> yBindable() { return QBindable<int>(&y); } + + Q_OBJECT_BINDABLE_PROPERTY(PropertyTester, int, xNotified, &PropertyTester::xNotifiedChanged) + Q_OBJECT_BINDABLE_PROPERTY(PropertyTester, int, yNotified, &PropertyTester::yNotifiedChanged) + + QBindable<int> xNotifiedBindable() { return QBindable<int>(&xNotified); } + QBindable<int> yNotifiedBindable() { return QBindable<int>(&yNotified); } + +private: + int m_xOld = 0; + int m_yOld = 0; +}; + +#endif // PROPERTYTESTER_H |