From bd520ccc3c5742e7af61fef66bab96575b7b67ac Mon Sep 17 00:00:00 2001 From: Maximilian Goldstein Date: Fri, 29 Jan 2021 09:18:46 +0100 Subject: Import qproperty benchmarks from private repo Change-Id: Icff5685b921f8a99acfeda1d79bb03ee652aa107 Reviewed-by: Ulf Hermann --- tests/benchmarks/corelib/kernel/CMakeLists.txt | 1 + .../corelib/kernel/qproperty/CMakeLists.txt | 8 + tests/benchmarks/corelib/kernel/qproperty/main.cpp | 231 +++++++++++++++++++++ .../corelib/kernel/qproperty/propertytester.h | 83 ++++++++ 4 files changed, 323 insertions(+) create mode 100644 tests/benchmarks/corelib/kernel/qproperty/CMakeLists.txt create mode 100644 tests/benchmarks/corelib/kernel/qproperty/main.cpp create mode 100644 tests/benchmarks/corelib/kernel/qproperty/propertytester.h (limited to 'tests/benchmarks/corelib/kernel') diff --git a/tests/benchmarks/corelib/kernel/CMakeLists.txt b/tests/benchmarks/corelib/kernel/CMakeLists.txt index 4bfdc63823..34d457bb21 100644 --- a/tests/benchmarks/corelib/kernel/CMakeLists.txt +++ b/tests/benchmarks/corelib/kernel/CMakeLists.txt @@ -5,6 +5,7 @@ add_subdirectory(qmetatype) add_subdirectory(qvariant) add_subdirectory(qcoreapplication) add_subdirectory(qtimer_vs_qmetaobject) +add_subdirectory(qproperty) if(TARGET Qt::Widgets) add_subdirectory(qmetaobject) add_subdirectory(qobject) diff --git a/tests/benchmarks/corelib/kernel/qproperty/CMakeLists.txt b/tests/benchmarks/corelib/kernel/qproperty/CMakeLists.txt new file mode 100644 index 0000000000..d6fc1c5a14 --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qproperty/CMakeLists.txt @@ -0,0 +1,8 @@ +qt_internal_add_benchmark(tst_bench_qproperty + SOURCES + main.cpp + propertytester.h + PUBLIC_LIBRARIES + Qt::Core + Qt::Test +) diff --git a/tests/benchmarks/corelib/kernel/qproperty/main.cpp b/tests/benchmarks/corelib/kernel/qproperty/main.cpp new file mode 100644 index 0000000000..5d6db35d2b --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qproperty/main.cpp @@ -0,0 +1,231 @@ +/**************************************************************************** +** +** 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 +#include + +#include + +#include "propertytester.h" + +class PropertyBenchmark : public QObject +{ + Q_OBJECT +private slots: + void cppOldBinding(); + void cppOldBindingReadOnce(); + void cppOldBindingDirect(); + void cppOldBindingDirectReadOnce(); + + void cppNewBinding(); + void cppNewBindingReadOnce(); + void cppNewBindingDirect(); + void cppNewBindingDirectReadOnce(); + + void cppNotifying(); + void cppNotifyingReadOnce(); + void cppNotifyingDirect(); + void cppNotifyingDirectReadOnce(); +}; + +void PropertyBenchmark::cppOldBinding() +{ + QScopedPointer tester {new PropertyTester}; + auto connection = connect(tester.data(), &PropertyTester::xOldChanged, + tester.data(), [&]() { tester->setYOld(tester->xOld()); }); + + QCOMPARE(tester->property("yOld").toInt(), 0); + int i = 0; + QBENCHMARK { + tester->setProperty("xOld", ++i); + if (tester->property("yOld").toInt() != i) + QFAIL("boo"); + } + + QObject::disconnect(connection); +} + +void PropertyBenchmark::cppOldBindingDirect() +{ + QScopedPointer tester {new PropertyTester}; + auto connection = connect(tester.data(), &PropertyTester::xOldChanged, + tester.data(), [&]() { tester->setYOld(tester->xOld()); }); + + QCOMPARE(tester->yOld(), 0); + int i = 0; + QBENCHMARK { + tester->setXOld(++i); + if (tester->yOld() != i) + QFAIL("boo"); + } + + QObject::disconnect(connection); +} + +void PropertyBenchmark::cppOldBindingReadOnce() +{ + QScopedPointer tester {new PropertyTester}; + auto connection = connect(tester.data(), &PropertyTester::xOldChanged, + tester.data(), [&]() { tester->setYOld(tester->xOld()); }); + + QCOMPARE(tester->property("yOld").toInt(), 0); + int i = 0; + QBENCHMARK { + tester->setProperty("xOld", ++i); + } + + QCOMPARE(tester->property("yOld").toInt(), i); + QObject::disconnect(connection); +} + +void PropertyBenchmark::cppOldBindingDirectReadOnce() +{ + QScopedPointer tester {new PropertyTester}; + auto connection = connect(tester.data(), &PropertyTester::xOldChanged, + tester.data(), [&]() { tester->setYOld(tester->xOld()); }); + + QCOMPARE(tester->yOld(), 0); + int i = 0; + QBENCHMARK { + tester->setXOld(++i); + } + + QCOMPARE(tester->yOld(), i); + QObject::disconnect(connection); +} + +void PropertyBenchmark::cppNewBinding() +{ + QScopedPointer tester {new PropertyTester}; + tester->y.setBinding([&](){return tester->x.value();}); + + QCOMPARE(tester->property("y").toInt(), 0); + int i = 0; + QBENCHMARK { + tester->setProperty("x", ++i); + if (tester->property("y").toInt() != i) + QFAIL("boo"); + } +} + +void PropertyBenchmark::cppNewBindingDirect() +{ + QScopedPointer tester {new PropertyTester}; + tester->y.setBinding([&](){return tester->x.value();}); + QCOMPARE(tester->y.value(), 0); + int i = 0; + QBENCHMARK { + tester->x = ++i; + if (tester->y.value() != i) + QFAIL("boo"); + } +} + +void PropertyBenchmark::cppNewBindingReadOnce() +{ + QScopedPointer tester {new PropertyTester}; + tester->y.setBinding([&](){return tester->x.value();}); + + QCOMPARE(tester->property("y").toInt(), 0); + int i = 0; + QBENCHMARK { + tester->setProperty("x", ++i); + } + + QCOMPARE(tester->property("y").toInt(), i); +} + +void PropertyBenchmark::cppNewBindingDirectReadOnce() +{ + QScopedPointer tester {new PropertyTester}; + tester->y.setBinding([&](){return tester->x.value();}); + QCOMPARE(tester->y.value(), 0); + int i = 0; + QBENCHMARK { + tester->x = ++i; + } + + QCOMPARE(tester->y.value(), i); +} + +void PropertyBenchmark::cppNotifying() +{ + QScopedPointer tester {new PropertyTester}; + tester->yNotified.setBinding([&](){return tester->xNotified.value();}); + + QCOMPARE(tester->property("yNotified").toInt(), 0); + int i = 0; + QBENCHMARK { + tester->setProperty("xNotified", ++i); + if (tester->property("yNotified").toInt() != i) + QFAIL("boo"); + } +} + +void PropertyBenchmark::cppNotifyingDirect() +{ + QScopedPointer tester {new PropertyTester}; + tester->yNotified.setBinding([&](){return tester->xNotified.value();}); + QCOMPARE(tester->yNotified.value(), 0); + int i = 0; + QBENCHMARK { + tester->xNotified.setValue(++i); + if (tester->yNotified.value() != i) + QFAIL("boo"); + } +} + +void PropertyBenchmark::cppNotifyingReadOnce() +{ + QScopedPointer tester {new PropertyTester}; + tester->yNotified.setBinding([&](){return tester->xNotified.value();}); + + QCOMPARE(tester->property("yNotified").toInt(), 0); + int i = 0; + QBENCHMARK { + tester->setProperty("xNotified", ++i); + } + + QCOMPARE(tester->property("yNotified").toInt(), i); +} + +void PropertyBenchmark::cppNotifyingDirectReadOnce() +{ + QScopedPointer tester {new PropertyTester}; + tester->yNotified.setBinding([&](){return tester->xNotified.value();}); + QCOMPARE(tester->yNotified.value(), 0); + int i = 0; + QBENCHMARK { + tester->xNotified.setValue(++i); + } + + QCOMPARE(tester->yNotified.value(), i); +} + +QTEST_MAIN(PropertyBenchmark) +#include "main.moc" diff --git a/tests/benchmarks/corelib/kernel/qproperty/propertytester.h b/tests/benchmarks/corelib/kernel/qproperty/propertytester.h new file mode 100644 index 0000000000..daf55f8396 --- /dev/null +++ b/tests/benchmarks/corelib/kernel/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 +#include + +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 x; + QProperty y; + + QBindable xBindable() { return QBindable(&x); } + QBindable yBindable() { return QBindable(&y); } + + Q_OBJECT_BINDABLE_PROPERTY(PropertyTester, int, xNotified, &PropertyTester::xNotifiedChanged) + Q_OBJECT_BINDABLE_PROPERTY(PropertyTester, int, yNotified, &PropertyTester::yNotifiedChanged) + + QBindable xNotifiedBindable() { return QBindable(&xNotified); } + QBindable yNotifiedBindable() { return QBindable(&yNotified); } + +private: + int m_xOld = 0; + int m_yOld = 0; +}; + +#endif // PROPERTYTESTER_H -- cgit v1.2.3