From 9004a2412ba1f9976c2c61f01223dff852208c42 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 18 Aug 2021 11:48:29 +0200 Subject: Standardise layout and naming in corelib benchmarks Make file names match CMake's test names (and those follow dir-name) and class names follow tst_ClassName pattern when testing ClassName. Purge comments about the qmake configs the CMakeLists.txt are generated from. Purge empty constructors and init/cleanup methods of classes. Fix petty coding style violations. Add qdir/tree/, qurl, qbench and qset benchmarks to their parent directories' lists of subdirs. Fix unused return error from qurl benchmark. Change-Id: Ifc15a3a46e71cf82ad0637753517e0df34049763 Reviewed-by: Andrei Golubev Reviewed-by: Thiago Macieira --- .../corelib/kernel/events/CMakeLists.txt | 7 +- tests/benchmarks/corelib/kernel/events/main.cpp | 174 ---------- .../corelib/kernel/events/tst_bench_events.cpp | 174 ++++++++++ .../corelib/kernel/qcoreapplication/CMakeLists.txt | 7 +- .../corelib/kernel/qcoreapplication/main.cpp | 69 ---- .../tst_bench_qcoreapplication.cpp | 69 ++++ .../corelib/kernel/qmetaobject/CMakeLists.txt | 7 +- .../benchmarks/corelib/kernel/qmetaobject/main.cpp | 252 -------------- .../kernel/qmetaobject/tst_bench_qmetaobject.cpp | 241 +++++++++++++ .../corelib/kernel/qmetatype/CMakeLists.txt | 7 +- .../kernel/qmetatype/tst_bench_qmetatype.cpp | 324 ++++++++++++++++++ .../corelib/kernel/qmetatype/tst_qmetatype.cpp | 324 ------------------ .../corelib/kernel/qobject/CMakeLists.txt | 7 +- tests/benchmarks/corelib/kernel/qobject/main.cpp | 310 ----------------- .../corelib/kernel/qobject/tst_bench_qobject.cpp | 310 +++++++++++++++++ .../corelib/kernel/qproperty/CMakeLists.txt | 2 +- tests/benchmarks/corelib/kernel/qproperty/main.cpp | 231 ------------- .../kernel/qproperty/tst_bench_qproperty.cpp | 232 +++++++++++++ .../corelib/kernel/qvariant/CMakeLists.txt | 4 +- .../corelib/kernel/qvariant/tst_bench_qvariant.cpp | 381 +++++++++++++++++++++ .../corelib/kernel/qvariant/tst_qvariant.cpp | 381 --------------------- .../kernel/qwineventnotifier/CMakeLists.txt | 7 +- .../corelib/kernel/qwineventnotifier/main.cpp | 136 -------- .../tst_bench_qwineventnotifier.cpp | 136 ++++++++ 24 files changed, 1875 insertions(+), 1917 deletions(-) delete mode 100644 tests/benchmarks/corelib/kernel/events/main.cpp create mode 100644 tests/benchmarks/corelib/kernel/events/tst_bench_events.cpp delete mode 100644 tests/benchmarks/corelib/kernel/qcoreapplication/main.cpp create mode 100644 tests/benchmarks/corelib/kernel/qcoreapplication/tst_bench_qcoreapplication.cpp delete mode 100644 tests/benchmarks/corelib/kernel/qmetaobject/main.cpp create mode 100644 tests/benchmarks/corelib/kernel/qmetaobject/tst_bench_qmetaobject.cpp create mode 100644 tests/benchmarks/corelib/kernel/qmetatype/tst_bench_qmetatype.cpp delete mode 100644 tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp delete mode 100644 tests/benchmarks/corelib/kernel/qobject/main.cpp create mode 100644 tests/benchmarks/corelib/kernel/qobject/tst_bench_qobject.cpp delete mode 100644 tests/benchmarks/corelib/kernel/qproperty/main.cpp create mode 100644 tests/benchmarks/corelib/kernel/qproperty/tst_bench_qproperty.cpp create mode 100644 tests/benchmarks/corelib/kernel/qvariant/tst_bench_qvariant.cpp delete mode 100644 tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp delete mode 100644 tests/benchmarks/corelib/kernel/qwineventnotifier/main.cpp create mode 100644 tests/benchmarks/corelib/kernel/qwineventnotifier/tst_bench_qwineventnotifier.cpp (limited to 'tests/benchmarks/corelib/kernel') diff --git a/tests/benchmarks/corelib/kernel/events/CMakeLists.txt b/tests/benchmarks/corelib/kernel/events/CMakeLists.txt index 41add9350e..b5440891ee 100644 --- a/tests/benchmarks/corelib/kernel/events/CMakeLists.txt +++ b/tests/benchmarks/corelib/kernel/events/CMakeLists.txt @@ -1,15 +1,10 @@ -# Generated from events.pro. - ##################################################################### ## tst_bench_events Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_events SOURCES - main.cpp + tst_bench_events.cpp PUBLIC_LIBRARIES Qt::Test ) - -#### Keys ignored in scope 1:.:.:events.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/kernel/events/main.cpp b/tests/benchmarks/corelib/kernel/events/main.cpp deleted file mode 100644 index 973d96261c..0000000000 --- a/tests/benchmarks/corelib/kernel/events/main.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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 - -class PingPong : public QObject -{ -public: - void setPeer(QObject *peer); - void resetCounter() {m_counter = 100;} - -protected: - bool event(QEvent *e) override; - -private: - QObject *m_peer; - int m_counter; -}; - -void PingPong::setPeer(QObject *peer) -{ - m_peer = peer; - m_counter = 100; -} - -bool PingPong::event(QEvent *) -{ - --m_counter; - if (m_counter > 0) { - QEvent *e = new QEvent(QEvent::User); - QCoreApplication::postEvent(m_peer, e); - } else { - QTestEventLoop::instance().exitLoop(); - } - return true; -} - -class EventTester : public QObject -{ -public: - int foo(int bar); - -protected: - bool event(QEvent *e) override; -}; - -bool EventTester::event(QEvent *e) -{ - if (e->type() == QEvent::User+1) - return foo(e->type()) != 0; - return false; -} - -int EventTester::foo(int bar) -{ - return bar + 1; -} - -class EventsBench : public QObject -{ - Q_OBJECT - -private slots: - void initTestCase(); - void cleanupTestCase(); - - void noEvent(); - void sendEvent_data(); - void sendEvent(); - void postEvent_data(); - void postEvent(); -}; - -void EventsBench::initTestCase() -{ -} - -void EventsBench::cleanupTestCase() -{ -} - -void EventsBench::noEvent() -{ - EventTester tst; - int val = 0; - QBENCHMARK { - val += tst.foo(1); - } -} - -void EventsBench::sendEvent_data() -{ - QTest::addColumn("filterEvents"); - QTest::newRow("no eventfilter") << false; - QTest::newRow("eventfilter") << true; -} - -void EventsBench::sendEvent() -{ - QFETCH(bool, filterEvents); - EventTester tst; - if (filterEvents) - tst.installEventFilter(this); - QEvent evt(QEvent::Type(QEvent::User+1)); - QBENCHMARK { - QCoreApplication::sendEvent(&tst, &evt); - } -} - -void EventsBench::postEvent_data() -{ - QTest::addColumn("filterEvents"); - // The first time an eventloop is executed, the case runs radically slower at least - // on some platforms, so test the "no eventfilter" case to get a comparable results - // with the "eventfilter" case. - QTest::newRow("first time, no eventfilter") << false; - QTest::newRow("no eventfilter") << false; - QTest::newRow("eventfilter") << true; -} - -void EventsBench::postEvent() -{ - QFETCH(bool, filterEvents); - PingPong ping; - PingPong pong; - ping.setPeer(&pong); - pong.setPeer(&ping); - if (filterEvents) { - ping.installEventFilter(this); - pong.installEventFilter(this); - } - - QBENCHMARK { - // In case multiple iterations are done, event needs to be created inside the QBENCHMARK, - // or it gets deleted once first iteration exits and can cause a crash. Similarly, - // ping and pong need their counters reset. - QEvent *e = new QEvent(QEvent::User); - ping.resetCounter(); - pong.resetCounter(); - QCoreApplication::postEvent(&ping, e); - QTestEventLoop::instance().enterLoop( 61 ); - } -} - -QTEST_MAIN(EventsBench) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/kernel/events/tst_bench_events.cpp b/tests/benchmarks/corelib/kernel/events/tst_bench_events.cpp new file mode 100644 index 0000000000..cfe5b1bcd1 --- /dev/null +++ b/tests/benchmarks/corelib/kernel/events/tst_bench_events.cpp @@ -0,0 +1,174 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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 + +class PingPong : public QObject +{ +public: + void setPeer(QObject *peer); + void resetCounter() {m_counter = 100;} + +protected: + bool event(QEvent *e) override; + +private: + QObject *m_peer; + int m_counter; +}; + +void PingPong::setPeer(QObject *peer) +{ + m_peer = peer; + m_counter = 100; +} + +bool PingPong::event(QEvent *) +{ + --m_counter; + if (m_counter > 0) { + QEvent *e = new QEvent(QEvent::User); + QCoreApplication::postEvent(m_peer, e); + } else { + QTestEventLoop::instance().exitLoop(); + } + return true; +} + +class EventTester : public QObject +{ +public: + int foo(int bar); + +protected: + bool event(QEvent *e) override; +}; + +bool EventTester::event(QEvent *e) +{ + if (e->type() == QEvent::User+1) + return foo(e->type()) != 0; + return false; +} + +int EventTester::foo(int bar) +{ + return bar + 1; +} + +class EventsBench : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + void cleanupTestCase(); + + void noEvent(); + void sendEvent_data(); + void sendEvent(); + void postEvent_data(); + void postEvent(); +}; + +void EventsBench::initTestCase() +{ +} + +void EventsBench::cleanupTestCase() +{ +} + +void EventsBench::noEvent() +{ + EventTester tst; + int val = 0; + QBENCHMARK { + val += tst.foo(1); + } +} + +void EventsBench::sendEvent_data() +{ + QTest::addColumn("filterEvents"); + QTest::newRow("no eventfilter") << false; + QTest::newRow("eventfilter") << true; +} + +void EventsBench::sendEvent() +{ + QFETCH(bool, filterEvents); + EventTester tst; + if (filterEvents) + tst.installEventFilter(this); + QEvent evt(QEvent::Type(QEvent::User+1)); + QBENCHMARK { + QCoreApplication::sendEvent(&tst, &evt); + } +} + +void EventsBench::postEvent_data() +{ + QTest::addColumn("filterEvents"); + // The first time an eventloop is executed, the case runs radically slower at least + // on some platforms, so test the "no eventfilter" case to get a comparable results + // with the "eventfilter" case. + QTest::newRow("first time, no eventfilter") << false; + QTest::newRow("no eventfilter") << false; + QTest::newRow("eventfilter") << true; +} + +void EventsBench::postEvent() +{ + QFETCH(bool, filterEvents); + PingPong ping; + PingPong pong; + ping.setPeer(&pong); + pong.setPeer(&ping); + if (filterEvents) { + ping.installEventFilter(this); + pong.installEventFilter(this); + } + + QBENCHMARK { + // In case multiple iterations are done, event needs to be created inside the QBENCHMARK, + // or it gets deleted once first iteration exits and can cause a crash. Similarly, + // ping and pong need their counters reset. + QEvent *e = new QEvent(QEvent::User); + ping.resetCounter(); + pong.resetCounter(); + QCoreApplication::postEvent(&ping, e); + QTestEventLoop::instance().enterLoop( 61 ); + } +} + +QTEST_MAIN(EventsBench) + +#include "tst_bench_events.moc" diff --git a/tests/benchmarks/corelib/kernel/qcoreapplication/CMakeLists.txt b/tests/benchmarks/corelib/kernel/qcoreapplication/CMakeLists.txt index 1618997909..0872bccf60 100644 --- a/tests/benchmarks/corelib/kernel/qcoreapplication/CMakeLists.txt +++ b/tests/benchmarks/corelib/kernel/qcoreapplication/CMakeLists.txt @@ -1,15 +1,10 @@ -# Generated from qcoreapplication.pro. - ##################################################################### ## tst_bench_qcoreapplication Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qcoreapplication SOURCES - main.cpp + tst_bench_qcoreapplication.cpp PUBLIC_LIBRARIES Qt::Test ) - -#### Keys ignored in scope 1:.:.:qcoreapplication.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/kernel/qcoreapplication/main.cpp b/tests/benchmarks/corelib/kernel/qcoreapplication/main.cpp deleted file mode 100644 index 018f689785..0000000000 --- a/tests/benchmarks/corelib/kernel/qcoreapplication/main.cpp +++ /dev/null @@ -1,69 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2011 Robin Burchell -** 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 - -class QCoreApplicationBenchmark : public QObject -{ -Q_OBJECT -private slots: - void event_posting_benchmark_data(); - void event_posting_benchmark(); -}; - -void QCoreApplicationBenchmark::event_posting_benchmark_data() -{ - QTest::addColumn("size"); - QTest::newRow("50 events") << 50; - QTest::newRow("100 events") << 100; - QTest::newRow("200 events") << 200; - QTest::newRow("1000 events") << 1000; - QTest::newRow("10000 events") << 10000; - QTest::newRow("100000 events") << 100000; - QTest::newRow("1000000 events") << 1000000; -} - -void QCoreApplicationBenchmark::event_posting_benchmark() -{ - QFETCH(int, size); - - int type = QEvent::registerEventType(); - QCoreApplication *app = QCoreApplication::instance(); - - // benchmark posting & sending events - QBENCHMARK { - for (int i = 0; i < size; ++i) - QCoreApplication::postEvent(app, new QEvent(QEvent::Type(type))); - QCoreApplication::sendPostedEvents(); - } -} - -QTEST_MAIN(QCoreApplicationBenchmark) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/kernel/qcoreapplication/tst_bench_qcoreapplication.cpp b/tests/benchmarks/corelib/kernel/qcoreapplication/tst_bench_qcoreapplication.cpp new file mode 100644 index 0000000000..86047a0b07 --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qcoreapplication/tst_bench_qcoreapplication.cpp @@ -0,0 +1,69 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Robin Burchell +** 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 + +class tst_QCoreApplication : public QObject +{ +Q_OBJECT +private slots: + void event_posting_benchmark_data(); + void event_posting_benchmark(); +}; + +void tst_QCoreApplication::event_posting_benchmark_data() +{ + QTest::addColumn("size"); + QTest::newRow("50 events") << 50; + QTest::newRow("100 events") << 100; + QTest::newRow("200 events") << 200; + QTest::newRow("1000 events") << 1000; + QTest::newRow("10000 events") << 10000; + QTest::newRow("100000 events") << 100000; + QTest::newRow("1000000 events") << 1000000; +} + +void tst_QCoreApplication::event_posting_benchmark() +{ + QFETCH(int, size); + + int type = QEvent::registerEventType(); + QCoreApplication *app = QCoreApplication::instance(); + + // benchmark posting & sending events + QBENCHMARK { + for (int i = 0; i < size; ++i) + QCoreApplication::postEvent(app, new QEvent(QEvent::Type(type))); + QCoreApplication::sendPostedEvents(); + } +} + +QTEST_MAIN(tst_QCoreApplication) + +#include "tst_bench_qcoreapplication.moc" diff --git a/tests/benchmarks/corelib/kernel/qmetaobject/CMakeLists.txt b/tests/benchmarks/corelib/kernel/qmetaobject/CMakeLists.txt index db4c3ab12e..2afd390439 100644 --- a/tests/benchmarks/corelib/kernel/qmetaobject/CMakeLists.txt +++ b/tests/benchmarks/corelib/kernel/qmetaobject/CMakeLists.txt @@ -1,17 +1,12 @@ -# Generated from qmetaobject.pro. - ##################################################################### ## tst_bench_qmetaobject Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qmetaobject SOURCES - main.cpp + tst_bench_qmetaobject.cpp PUBLIC_LIBRARIES Qt::Gui Qt::Test Qt::Widgets ) - -#### Keys ignored in scope 1:.:.:qmetaobject.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/kernel/qmetaobject/main.cpp b/tests/benchmarks/corelib/kernel/qmetaobject/main.cpp deleted file mode 100644 index 262dca7d52..0000000000 --- a/tests/benchmarks/corelib/kernel/qmetaobject/main.cpp +++ /dev/null @@ -1,252 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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 - -class LotsOfSignals : public QObject -{ - Q_OBJECT -public: - LotsOfSignals() {} - -signals: - void extraSignal1(); - void extraSignal2(); - void extraSignal3(); - void extraSignal4(); - void extraSignal5(); - void extraSignal6(); - void extraSignal7(); - void extraSignal8(); - void extraSignal9(); - void extraSignal10(); - void extraSignal12(); - void extraSignal13(); - void extraSignal14(); - void extraSignal15(); - void extraSignal16(); - void extraSignal17(); - void extraSignal18(); - void extraSignal19(); - void extraSignal20(); - void extraSignal21(); - void extraSignal22(); - void extraSignal23(); - void extraSignal24(); - void extraSignal25(); - void extraSignal26(); - void extraSignal27(); - void extraSignal28(); - void extraSignal29(); - void extraSignal30(); - void extraSignal31(); - void extraSignal32(); - void extraSignal33(); - void extraSignal34(); - void extraSignal35(); - void extraSignal36(); - void extraSignal37(); - void extraSignal38(); - void extraSignal39(); - void extraSignal40(); - void extraSignal41(); - void extraSignal42(); - void extraSignal43(); - void extraSignal44(); - void extraSignal45(); - void extraSignal46(); - void extraSignal47(); - void extraSignal48(); - void extraSignal49(); - void extraSignal50(); - void extraSignal51(); - void extraSignal52(); - void extraSignal53(); - void extraSignal54(); - void extraSignal55(); - void extraSignal56(); - void extraSignal57(); - void extraSignal58(); - void extraSignal59(); - void extraSignal60(); - void extraSignal61(); - void extraSignal62(); - void extraSignal63(); - void extraSignal64(); - void extraSignal65(); - void extraSignal66(); - void extraSignal67(); - void extraSignal68(); - void extraSignal69(); - void extraSignal70(); -}; - -class tst_qmetaobject: public QObject -{ -Q_OBJECT -private slots: - void initTestCase(); - void cleanupTestCase(); - - void indexOfProperty_data(); - void indexOfProperty(); - void indexOfMethod_data(); - void indexOfMethod(); - void indexOfSignal_data(); - void indexOfSignal(); - void indexOfSlot_data(); - void indexOfSlot(); - - void unconnected_data(); - void unconnected(); -}; - -void tst_qmetaobject::initTestCase() -{ -} - -void tst_qmetaobject::cleanupTestCase() -{ -} - -void tst_qmetaobject::indexOfProperty_data() -{ - QTest::addColumn("name"); - const QMetaObject *mo = &QTreeView::staticMetaObject; - for (int i = 0; i < mo->propertyCount(); ++i) { - QMetaProperty prop = mo->property(i); - QTest::newRow(prop.name()) << QByteArray(prop.name()); - } -} - -void tst_qmetaobject::indexOfProperty() -{ - QFETCH(QByteArray, name); - const char *p = name.constData(); - const QMetaObject *mo = &QTreeView::staticMetaObject; - QBENCHMARK { - (void)mo->indexOfProperty(p); - } -} - -void tst_qmetaobject::indexOfMethod_data() -{ - QTest::addColumn("method"); - const QMetaObject *mo = &QTreeView::staticMetaObject; - for (int i = 0; i < mo->methodCount(); ++i) { - QMetaMethod method = mo->method(i); - QByteArray sig = method.methodSignature(); - QTest::newRow(sig) << sig; - } -} - -void tst_qmetaobject::indexOfMethod() -{ - QFETCH(QByteArray, method); - const char *p = method.constData(); - const QMetaObject *mo = &QTreeView::staticMetaObject; - QBENCHMARK { - (void)mo->indexOfMethod(p); - } -} - -void tst_qmetaobject::indexOfSignal_data() -{ - QTest::addColumn("signal"); - const QMetaObject *mo = &QTreeView::staticMetaObject; - for (int i = 0; i < mo->methodCount(); ++i) { - QMetaMethod method = mo->method(i); - if (method.methodType() != QMetaMethod::Signal) - continue; - QByteArray sig = method.methodSignature(); - QTest::newRow(sig) << sig; - } -} - -void tst_qmetaobject::indexOfSignal() -{ - QFETCH(QByteArray, signal); - const char *p = signal.constData(); - const QMetaObject *mo = &QTreeView::staticMetaObject; - QBENCHMARK { - (void)mo->indexOfSignal(p); - } -} - -void tst_qmetaobject::indexOfSlot_data() -{ - QTest::addColumn("slot"); - const QMetaObject *mo = &QTreeView::staticMetaObject; - for (int i = 0; i < mo->methodCount(); ++i) { - QMetaMethod method = mo->method(i); - if (method.methodType() != QMetaMethod::Slot) - continue; - QByteArray sig = method.methodSignature(); - QTest::newRow(sig) << sig; - } -} - -void tst_qmetaobject::indexOfSlot() -{ - QFETCH(QByteArray, slot); - const char *p = slot.constData(); - const QMetaObject *mo = &QTreeView::staticMetaObject; - QBENCHMARK { - (void)mo->indexOfSlot(p); - } -} - -void tst_qmetaobject::unconnected_data() -{ - QTest::addColumn("signal_index"); - QTest::newRow("signal--9") << 9; - QTest::newRow("signal--32") << 32; - QTest::newRow("signal--33") << 33; - QTest::newRow("signal--64") << 64; - QTest::newRow("signal--65") << 65; - QTest::newRow("signal--70") << 70; -} - -void tst_qmetaobject::unconnected() -{ - LotsOfSignals *obj = new LotsOfSignals; - QFETCH(int, signal_index); - // 74: 70 signals in LotsOfSignals, 2 signals, 1 slot + 1 invokable in QObject - QCOMPARE(obj->metaObject()->methodCount(), 74); - void *v; - QBENCHMARK { - // Add two because QObject has one slot and one invokable - QMetaObject::metacall(obj, QMetaObject::InvokeMetaMethod, signal_index + 2, &v); - } - delete obj; -} - -QTEST_MAIN(tst_qmetaobject) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/kernel/qmetaobject/tst_bench_qmetaobject.cpp b/tests/benchmarks/corelib/kernel/qmetaobject/tst_bench_qmetaobject.cpp new file mode 100644 index 0000000000..7da721042b --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qmetaobject/tst_bench_qmetaobject.cpp @@ -0,0 +1,241 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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 + +class LotsOfSignals : public QObject // for the unconnected() test +{ + Q_OBJECT +public: + LotsOfSignals() {} + +signals: + void extraSignal1(); + void extraSignal2(); + void extraSignal3(); + void extraSignal4(); + void extraSignal5(); + void extraSignal6(); + void extraSignal7(); + void extraSignal8(); + void extraSignal9(); + void extraSignal10(); + void extraSignal12(); + void extraSignal13(); + void extraSignal14(); + void extraSignal15(); + void extraSignal16(); + void extraSignal17(); + void extraSignal18(); + void extraSignal19(); + void extraSignal20(); + void extraSignal21(); + void extraSignal22(); + void extraSignal23(); + void extraSignal24(); + void extraSignal25(); + void extraSignal26(); + void extraSignal27(); + void extraSignal28(); + void extraSignal29(); + void extraSignal30(); + void extraSignal31(); + void extraSignal32(); + void extraSignal33(); + void extraSignal34(); + void extraSignal35(); + void extraSignal36(); + void extraSignal37(); + void extraSignal38(); + void extraSignal39(); + void extraSignal40(); + void extraSignal41(); + void extraSignal42(); + void extraSignal43(); + void extraSignal44(); + void extraSignal45(); + void extraSignal46(); + void extraSignal47(); + void extraSignal48(); + void extraSignal49(); + void extraSignal50(); + void extraSignal51(); + void extraSignal52(); + void extraSignal53(); + void extraSignal54(); + void extraSignal55(); + void extraSignal56(); + void extraSignal57(); + void extraSignal58(); + void extraSignal59(); + void extraSignal60(); + void extraSignal61(); + void extraSignal62(); + void extraSignal63(); + void extraSignal64(); + void extraSignal65(); + void extraSignal66(); + void extraSignal67(); + void extraSignal68(); + void extraSignal69(); + void extraSignal70(); +}; + +class tst_QMetaObject: public QObject +{ +Q_OBJECT +private slots: + void indexOfProperty_data(); + void indexOfProperty(); + void indexOfMethod_data(); + void indexOfMethod(); + void indexOfSignal_data(); + void indexOfSignal(); + void indexOfSlot_data(); + void indexOfSlot(); + + void unconnected_data(); + void unconnected(); +}; + +void tst_QMetaObject::indexOfProperty_data() +{ + QTest::addColumn("name"); + const QMetaObject *mo = &QTreeView::staticMetaObject; + for (int i = 0; i < mo->propertyCount(); ++i) { + QMetaProperty prop = mo->property(i); + QTest::newRow(prop.name()) << QByteArray(prop.name()); + } +} + +void tst_QMetaObject::indexOfProperty() +{ + QFETCH(QByteArray, name); + const char *p = name.constData(); + const QMetaObject *mo = &QTreeView::staticMetaObject; + QBENCHMARK { + (void)mo->indexOfProperty(p); + } +} + +void tst_QMetaObject::indexOfMethod_data() +{ + QTest::addColumn("method"); + const QMetaObject *mo = &QTreeView::staticMetaObject; + for (int i = 0; i < mo->methodCount(); ++i) { + QMetaMethod method = mo->method(i); + QByteArray sig = method.methodSignature(); + QTest::newRow(sig) << sig; + } +} + +void tst_QMetaObject::indexOfMethod() +{ + QFETCH(QByteArray, method); + const char *p = method.constData(); + const QMetaObject *mo = &QTreeView::staticMetaObject; + QBENCHMARK { + (void)mo->indexOfMethod(p); + } +} + +void tst_QMetaObject::indexOfSignal_data() +{ + QTest::addColumn("signal"); + const QMetaObject *mo = &QTreeView::staticMetaObject; + for (int i = 0; i < mo->methodCount(); ++i) { + QMetaMethod method = mo->method(i); + if (method.methodType() != QMetaMethod::Signal) + continue; + QByteArray sig = method.methodSignature(); + QTest::newRow(sig) << sig; + } +} + +void tst_QMetaObject::indexOfSignal() +{ + QFETCH(QByteArray, signal); + const char *p = signal.constData(); + const QMetaObject *mo = &QTreeView::staticMetaObject; + QBENCHMARK { + (void)mo->indexOfSignal(p); + } +} + +void tst_QMetaObject::indexOfSlot_data() +{ + QTest::addColumn("slot"); + const QMetaObject *mo = &QTreeView::staticMetaObject; + for (int i = 0; i < mo->methodCount(); ++i) { + QMetaMethod method = mo->method(i); + if (method.methodType() != QMetaMethod::Slot) + continue; + QByteArray sig = method.methodSignature(); + QTest::newRow(sig) << sig; + } +} + +void tst_QMetaObject::indexOfSlot() +{ + QFETCH(QByteArray, slot); + const char *p = slot.constData(); + const QMetaObject *mo = &QTreeView::staticMetaObject; + QBENCHMARK { + (void)mo->indexOfSlot(p); + } +} + +void tst_QMetaObject::unconnected_data() +{ + QTest::addColumn("signal_index"); + QTest::newRow("signal--9") << 9; + QTest::newRow("signal--32") << 32; + QTest::newRow("signal--33") << 33; + QTest::newRow("signal--64") << 64; + QTest::newRow("signal--65") << 65; + QTest::newRow("signal--70") << 70; +} + +void tst_QMetaObject::unconnected() +{ + LotsOfSignals *obj = new LotsOfSignals; + QFETCH(int, signal_index); + // 74: 70 signals in LotsOfSignals, 2 signals, 1 slot + 1 invokable in QObject + QCOMPARE(obj->metaObject()->methodCount(), 74); + void *v; + QBENCHMARK { + // Add two because QObject has one slot and one invokable + QMetaObject::metacall(obj, QMetaObject::InvokeMetaMethod, signal_index + 2, &v); + } + delete obj; +} + +QTEST_MAIN(tst_QMetaObject) + +#include "tst_bench_qmetaobject.moc" diff --git a/tests/benchmarks/corelib/kernel/qmetatype/CMakeLists.txt b/tests/benchmarks/corelib/kernel/qmetatype/CMakeLists.txt index ae4bc9c906..8fd20ee111 100644 --- a/tests/benchmarks/corelib/kernel/qmetatype/CMakeLists.txt +++ b/tests/benchmarks/corelib/kernel/qmetatype/CMakeLists.txt @@ -1,15 +1,10 @@ -# Generated from qmetatype.pro. - ##################################################################### ## tst_bench_qmetatype Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qmetatype SOURCES - tst_qmetatype.cpp + tst_bench_qmetatype.cpp PUBLIC_LIBRARIES Qt::Test ) - -#### Keys ignored in scope 1:.:.:qmetatype.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/kernel/qmetatype/tst_bench_qmetatype.cpp b/tests/benchmarks/corelib/kernel/qmetatype/tst_bench_qmetatype.cpp new file mode 100644 index 0000000000..c273cd32a4 --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qmetatype/tst_bench_qmetatype.cpp @@ -0,0 +1,324 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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 + +class tst_QMetaType : public QObject +{ + Q_OBJECT + +public: + tst_QMetaType(); + virtual ~tst_QMetaType(); + +private slots: + void typeBuiltin_data(); + void typeBuiltin(); + void typeBuiltin_QByteArray_data(); + void typeBuiltin_QByteArray(); + void typeBuiltinNotNormalized_data(); + void typeBuiltinNotNormalized(); + void typeCustom(); + void typeCustomNotNormalized(); + void typeNotRegistered(); + void typeNotRegisteredNotNormalized(); + + void typeNameBuiltin_data(); + void typeNameBuiltin(); + void typeNameCustom(); + void typeNameNotRegistered(); + + void isRegisteredBuiltin_data(); + void isRegisteredBuiltin(); + void isRegisteredCustom(); + void isRegisteredNotRegistered(); + + void constructInPlace_data(); + void constructInPlace(); + void constructInPlaceCopy_data(); + void constructInPlaceCopy(); + void constructInPlaceCopyStaticLess_data(); + void constructInPlaceCopyStaticLess(); +}; + +tst_QMetaType::tst_QMetaType() +{ +} + +tst_QMetaType::~tst_QMetaType() +{ +} + +struct BigClass +{ + double n,i,e,r,o,b; +}; +Q_DECLARE_METATYPE(BigClass); + +void tst_QMetaType::typeBuiltin_data() +{ + QTest::addColumn("typeName"); + for (int i = 0; i < QMetaType::User; ++i) { + if (QMetaType metaType(i); metaType.isValid()) + QTest::newRow(metaType.name()) << QByteArray(metaType.name()); + } +} + +// QMetaType::type(const char *) +void tst_QMetaType::typeBuiltin() +{ + QFETCH(QByteArray, typeName); + const char *nm = typeName.constData(); + QBENCHMARK { + for (int i = 0; i < 100000; ++i) + QMetaType::fromName(nm); + } +} + +void tst_QMetaType::typeBuiltin_QByteArray_data() +{ + typeBuiltin_data(); +} + +// QMetaType::type(QByteArray) +void tst_QMetaType::typeBuiltin_QByteArray() +{ + QFETCH(QByteArray, typeName); + QBENCHMARK { + for (int i = 0; i < 100000; ++i) + QMetaType::fromName(typeName); + } +} + +void tst_QMetaType::typeBuiltinNotNormalized_data() +{ + QTest::addColumn("typeName"); + for (int i = 0; i < QMetaType::User; ++i) { + if (QMetaType metaType(i); metaType.isValid()) + QTest::newRow(metaType.name()) << QByteArray(metaType.name()).append(" "); + } +} + +void tst_QMetaType::typeBuiltinNotNormalized() +{ + QFETCH(QByteArray, typeName); + const char *nm = typeName.constData(); + QBENCHMARK { + for (int i = 0; i < 10000; ++i) + QMetaType::fromName(nm); + } +} + +struct Foo { int i; }; + +void tst_QMetaType::typeCustom() +{ + qRegisterMetaType("Foo"); + QBENCHMARK { + for (int i = 0; i < 10000; ++i) + QMetaType::fromName("Foo"); + } +} + +void tst_QMetaType::typeCustomNotNormalized() +{ + qRegisterMetaType("Foo"); + QBENCHMARK { + for (int i = 0; i < 10000; ++i) + QMetaType::fromName("Foo "); + } +} + +void tst_QMetaType::typeNotRegistered() +{ + Q_ASSERT(!QMetaType::fromName("Bar").isValid()); + QBENCHMARK { + for (int i = 0; i < 10000; ++i) + QMetaType::fromName("Bar"); + } +} + +void tst_QMetaType::typeNotRegisteredNotNormalized() +{ + Q_ASSERT(!QMetaType::fromName("Bar").isValid()); + QBENCHMARK { + for (int i = 0; i < 10000; ++i) + QMetaType::fromName("Bar "); + } +} + +void tst_QMetaType::typeNameBuiltin_data() +{ + QTest::addColumn("type"); + for (int i = 0; i < QMetaType::User; ++i) { + if (QMetaType metaType(i); metaType.isValid()) + QTest::newRow(metaType.name()) << i; + } +} + +void tst_QMetaType::typeNameBuiltin() +{ + QFETCH(int, type); + QBENCHMARK { + for (int i = 0; i < 500000; ++i) + QMetaType(type).name(); + } +} + +void tst_QMetaType::typeNameCustom() +{ + int type = qRegisterMetaType("Foo"); + QBENCHMARK { + for (int i = 0; i < 100000; ++i) + QMetaType(type).name(); + } +} + +void tst_QMetaType::typeNameNotRegistered() +{ + // We don't care much about this case, but test it anyway. + Q_ASSERT(QMetaType(-1).name() == nullptr); + QBENCHMARK { + for (int i = 0; i < 500000; ++i) + QMetaType(-1).name(); + } +} + +void tst_QMetaType::isRegisteredBuiltin_data() +{ + typeNameBuiltin_data(); +} + +void tst_QMetaType::isRegisteredBuiltin() +{ + QFETCH(int, type); + QBENCHMARK { + for (int i = 0; i < 500000; ++i) + QMetaType::isRegistered(type); + } +} + +void tst_QMetaType::isRegisteredCustom() +{ + int type = qRegisterMetaType("Foo"); + QBENCHMARK { + for (int i = 0; i < 100000; ++i) + QMetaType::isRegistered(type); + } +} + +void tst_QMetaType::isRegisteredNotRegistered() +{ + Q_ASSERT(QMetaType(-1).name() == nullptr); + QBENCHMARK { + for (int i = 0; i < 100000; ++i) + QMetaType::isRegistered(-1); + } +} + +void tst_QMetaType::constructInPlace_data() +{ + QTest::addColumn("typeId"); + for (int i = QMetaType::FirstCoreType; i <= QMetaType::LastCoreType; ++i) { + auto name = QMetaType(i).name(); + if (name && i != QMetaType::Void) + QTest::newRow(name) << i; + } + + QTest::newRow("custom") << qMetaTypeId(); + // GUI types are tested in tst_QGuiMetaType. +} + +void tst_QMetaType::constructInPlace() +{ + QFETCH(int, typeId); + const QMetaType metaType(typeId); + size_t size = metaType.sizeOf(); + void *storage = qMallocAligned(size, 2 * sizeof(qlonglong)); + QCOMPARE(metaType.construct(storage, /*copy=*/0), storage); + metaType.destruct(storage); + QBENCHMARK { + for (int i = 0; i < 100000; ++i) { + metaType.construct(storage, /*copy=*/0); + metaType.destruct(storage); + } + } + qFreeAligned(storage); +} + +void tst_QMetaType::constructInPlaceCopy_data() +{ + constructInPlace_data(); +} + +void tst_QMetaType::constructInPlaceCopy() +{ + QFETCH(int, typeId); + const QMetaType metaType(typeId); + size_t size = metaType.sizeOf(); + void *storage = qMallocAligned(size, 2 * sizeof(qlonglong)); + void *other = metaType.create(); + QCOMPARE(metaType.construct(storage, other), storage); + metaType.destruct(storage); + QBENCHMARK { + for (int i = 0; i < 100000; ++i) { + metaType.construct(storage, other); + metaType.destruct(storage); + } + } + metaType.destroy(other); + qFreeAligned(storage); +} + +void tst_QMetaType::constructInPlaceCopyStaticLess_data() +{ + constructInPlaceCopy_data(); +} + +void tst_QMetaType::constructInPlaceCopyStaticLess() +{ + QFETCH(int, typeId); + const QMetaType metaType(typeId); + size_t size = metaType.sizeOf(); + void *storage = qMallocAligned(size, 2 * sizeof(qlonglong)); + void *other = metaType.create(); + QCOMPARE(metaType.construct(storage, other), storage); + metaType.destruct(storage); + QBENCHMARK { + for (int i = 0; i < 100000; ++i) { + metaType.construct(storage, other); + metaType.destruct(storage); + } + } + metaType.destroy(other); + qFreeAligned(storage); +} + +QTEST_MAIN(tst_QMetaType) +#include "tst_bench_qmetatype.moc" diff --git a/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp deleted file mode 100644 index d41823de71..0000000000 --- a/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ /dev/null @@ -1,324 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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 - -class tst_QMetaType : public QObject -{ - Q_OBJECT - -public: - tst_QMetaType(); - virtual ~tst_QMetaType(); - -private slots: - void typeBuiltin_data(); - void typeBuiltin(); - void typeBuiltin_QByteArray_data(); - void typeBuiltin_QByteArray(); - void typeBuiltinNotNormalized_data(); - void typeBuiltinNotNormalized(); - void typeCustom(); - void typeCustomNotNormalized(); - void typeNotRegistered(); - void typeNotRegisteredNotNormalized(); - - void typeNameBuiltin_data(); - void typeNameBuiltin(); - void typeNameCustom(); - void typeNameNotRegistered(); - - void isRegisteredBuiltin_data(); - void isRegisteredBuiltin(); - void isRegisteredCustom(); - void isRegisteredNotRegistered(); - - void constructInPlace_data(); - void constructInPlace(); - void constructInPlaceCopy_data(); - void constructInPlaceCopy(); - void constructInPlaceCopyStaticLess_data(); - void constructInPlaceCopyStaticLess(); -}; - -tst_QMetaType::tst_QMetaType() -{ -} - -tst_QMetaType::~tst_QMetaType() -{ -} - -struct BigClass -{ - double n,i,e,r,o,b; -}; -Q_DECLARE_METATYPE(BigClass); - -void tst_QMetaType::typeBuiltin_data() -{ - QTest::addColumn("typeName"); - for (int i = 0; i < QMetaType::User; ++i) { - if (QMetaType metaType(i); metaType.isValid()) - QTest::newRow(metaType.name()) << QByteArray(metaType.name()); - } -} - -// QMetaType::type(const char *) -void tst_QMetaType::typeBuiltin() -{ - QFETCH(QByteArray, typeName); - const char *nm = typeName.constData(); - QBENCHMARK { - for (int i = 0; i < 100000; ++i) - QMetaType::fromName(nm); - } -} - -void tst_QMetaType::typeBuiltin_QByteArray_data() -{ - typeBuiltin_data(); -} - -// QMetaType::type(QByteArray) -void tst_QMetaType::typeBuiltin_QByteArray() -{ - QFETCH(QByteArray, typeName); - QBENCHMARK { - for (int i = 0; i < 100000; ++i) - QMetaType::fromName(typeName); - } -} - -void tst_QMetaType::typeBuiltinNotNormalized_data() -{ - QTest::addColumn("typeName"); - for (int i = 0; i < QMetaType::User; ++i) { - if (QMetaType metaType(i); metaType.isValid()) - QTest::newRow(metaType.name()) << QByteArray(metaType.name()).append(" "); - } -} - -void tst_QMetaType::typeBuiltinNotNormalized() -{ - QFETCH(QByteArray, typeName); - const char *nm = typeName.constData(); - QBENCHMARK { - for (int i = 0; i < 10000; ++i) - QMetaType::fromName(nm); - } -} - -struct Foo { int i; }; - -void tst_QMetaType::typeCustom() -{ - qRegisterMetaType("Foo"); - QBENCHMARK { - for (int i = 0; i < 10000; ++i) - QMetaType::fromName("Foo"); - } -} - -void tst_QMetaType::typeCustomNotNormalized() -{ - qRegisterMetaType("Foo"); - QBENCHMARK { - for (int i = 0; i < 10000; ++i) - QMetaType::fromName("Foo "); - } -} - -void tst_QMetaType::typeNotRegistered() -{ - Q_ASSERT(!QMetaType::fromName("Bar").isValid()); - QBENCHMARK { - for (int i = 0; i < 10000; ++i) - QMetaType::fromName("Bar"); - } -} - -void tst_QMetaType::typeNotRegisteredNotNormalized() -{ - Q_ASSERT(!QMetaType::fromName("Bar").isValid()); - QBENCHMARK { - for (int i = 0; i < 10000; ++i) - QMetaType::fromName("Bar "); - } -} - -void tst_QMetaType::typeNameBuiltin_data() -{ - QTest::addColumn("type"); - for (int i = 0; i < QMetaType::User; ++i) { - if (QMetaType metaType(i); metaType.isValid()) - QTest::newRow(metaType.name()) << i; - } -} - -void tst_QMetaType::typeNameBuiltin() -{ - QFETCH(int, type); - QBENCHMARK { - for (int i = 0; i < 500000; ++i) - QMetaType(type).name(); - } -} - -void tst_QMetaType::typeNameCustom() -{ - int type = qRegisterMetaType("Foo"); - QBENCHMARK { - for (int i = 0; i < 100000; ++i) - QMetaType(type).name(); - } -} - -void tst_QMetaType::typeNameNotRegistered() -{ - // We don't care much about this case, but test it anyway. - Q_ASSERT(QMetaType(-1).name() == nullptr); - QBENCHMARK { - for (int i = 0; i < 500000; ++i) - QMetaType(-1).name(); - } -} - -void tst_QMetaType::isRegisteredBuiltin_data() -{ - typeNameBuiltin_data(); -} - -void tst_QMetaType::isRegisteredBuiltin() -{ - QFETCH(int, type); - QBENCHMARK { - for (int i = 0; i < 500000; ++i) - QMetaType::isRegistered(type); - } -} - -void tst_QMetaType::isRegisteredCustom() -{ - int type = qRegisterMetaType("Foo"); - QBENCHMARK { - for (int i = 0; i < 100000; ++i) - QMetaType::isRegistered(type); - } -} - -void tst_QMetaType::isRegisteredNotRegistered() -{ - Q_ASSERT(QMetaType(-1).name() == nullptr); - QBENCHMARK { - for (int i = 0; i < 100000; ++i) - QMetaType::isRegistered(-1); - } -} - -void tst_QMetaType::constructInPlace_data() -{ - QTest::addColumn("typeId"); - for (int i = QMetaType::FirstCoreType; i <= QMetaType::LastCoreType; ++i) { - auto name = QMetaType(i).name(); - if (name && i != QMetaType::Void) - QTest::newRow(name) << i; - } - - QTest::newRow("custom") << qMetaTypeId(); - // GUI types are tested in tst_QGuiMetaType. -} - -void tst_QMetaType::constructInPlace() -{ - QFETCH(int, typeId); - const QMetaType metaType(typeId); - size_t size = metaType.sizeOf(); - void *storage = qMallocAligned(size, 2 * sizeof(qlonglong)); - QCOMPARE(metaType.construct(storage, /*copy=*/0), storage); - metaType.destruct(storage); - QBENCHMARK { - for (int i = 0; i < 100000; ++i) { - metaType.construct(storage, /*copy=*/0); - metaType.destruct(storage); - } - } - qFreeAligned(storage); -} - -void tst_QMetaType::constructInPlaceCopy_data() -{ - constructInPlace_data(); -} - -void tst_QMetaType::constructInPlaceCopy() -{ - QFETCH(int, typeId); - const QMetaType metaType(typeId); - size_t size = metaType.sizeOf(); - void *storage = qMallocAligned(size, 2 * sizeof(qlonglong)); - void *other = metaType.create(); - QCOMPARE(metaType.construct(storage, other), storage); - metaType.destruct(storage); - QBENCHMARK { - for (int i = 0; i < 100000; ++i) { - metaType.construct(storage, other); - metaType.destruct(storage); - } - } - metaType.destroy(other); - qFreeAligned(storage); -} - -void tst_QMetaType::constructInPlaceCopyStaticLess_data() -{ - constructInPlaceCopy_data(); -} - -void tst_QMetaType::constructInPlaceCopyStaticLess() -{ - QFETCH(int, typeId); - const QMetaType metaType(typeId); - size_t size = metaType.sizeOf(); - void *storage = qMallocAligned(size, 2 * sizeof(qlonglong)); - void *other = metaType.create(); - QCOMPARE(metaType.construct(storage, other), storage); - metaType.destruct(storage); - QBENCHMARK { - for (int i = 0; i < 100000; ++i) { - metaType.construct(storage, other); - metaType.destruct(storage); - } - } - metaType.destroy(other); - qFreeAligned(storage); -} - -QTEST_MAIN(tst_QMetaType) -#include "tst_qmetatype.moc" diff --git a/tests/benchmarks/corelib/kernel/qobject/CMakeLists.txt b/tests/benchmarks/corelib/kernel/qobject/CMakeLists.txt index ce834905b0..fb13e8a59e 100644 --- a/tests/benchmarks/corelib/kernel/qobject/CMakeLists.txt +++ b/tests/benchmarks/corelib/kernel/qobject/CMakeLists.txt @@ -1,18 +1,13 @@ -# Generated from qobject.pro. - ##################################################################### ## tst_bench_qobject Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qobject SOURCES - main.cpp + tst_bench_qobject.cpp object.cpp object.h PUBLIC_LIBRARIES Qt::Gui Qt::Test Qt::Widgets ) - -#### Keys ignored in scope 1:.:.:qobject.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/kernel/qobject/main.cpp b/tests/benchmarks/corelib/kernel/qobject/main.cpp deleted file mode 100644 index 918227f74e..0000000000 --- a/tests/benchmarks/corelib/kernel/qobject/main.cpp +++ /dev/null @@ -1,310 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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 "object.h" -#include -#include - -enum { - CreationDeletionBenckmarkConstant = 34567, - SignalsAndSlotsBenchmarkConstant = 456789 -}; - -class QObjectBenchmark : public QObject -{ -Q_OBJECT -private slots: - void signal_slot_benchmark(); - void signal_slot_benchmark_data(); - void signal_many_receivers(); - void signal_many_receivers_data(); - void qproperty_benchmark_data(); - void qproperty_benchmark(); - void dynamic_property_benchmark(); - void connect_disconnect_benchmark_data(); - void connect_disconnect_benchmark(); - void receiver_destroyed_benchmark(); - - void stdAllocator(); -}; - -class QObjectUsingStandardAllocator : public QObject -{ - Q_OBJECT -public: - QObjectUsingStandardAllocator() - { - } -}; - -template -inline void allocator() -{ - // We need to allocate certain amount of objects otherwise the new implementation - // may re-use the previous allocation, hiding the somehow high cost of allocation. It - // also helps us to reduce the noise ratio, which is high for memory allocation. - // - // The check depends on memory allocation performance, which is quite non-deterministic. - // When a new memory is requested, the new operator, depending on implementation, is trying - // to re-use existing, already allocated for the process memory. If there is not enough, it - // asks OS to give more. Of course the first case is faster then the second. In the same - // time, from an application perspective the first is also more likely. - // - // As a result, depending on which use-case one wants to test, it may be recommended to run this - // test in separation from others, to "force" expensive code path in the memory allocation. - // - // The time based results are heavily affected by background noise. One really needs to - // prepare OS (no other tasks, CPU and RAM reservations) to run this test, or use - // instruction counting which seems to be less fragile. - - const int count = 256 * 1024; - - QScopedPointer objects[count]; - QBENCHMARK_ONCE { - for (int i = 0; i < count; ++i) - objects[i].reset(new T); - for (int i = 0; i < count; ++i) - objects[i].reset(); - } -} - -void QObjectBenchmark::stdAllocator() -{ - allocator(); -} - -struct Functor { - void operator()(){} -}; - -void QObjectBenchmark::signal_slot_benchmark_data() -{ - QTest::addColumn("type"); - QTest::newRow("simple function") << 0; - QTest::newRow("single signal/slot") << 1; - QTest::newRow("multi signal/slot") << 2; - QTest::newRow("unconnected signal") << 3; - QTest::newRow("single signal/ptr") << 4; - QTest::newRow("functor") << 5; -} - -void QObjectBenchmark::signal_slot_benchmark() -{ - QFETCH(int, type); - - Object singleObject; - Object multiObject; - Functor functor; - singleObject.setObjectName("single"); - multiObject.setObjectName("multi"); - - if (type == 5) { - QObject::connect(&singleObject, &Object::signal0, functor); - } else if (type == 4) { - QObject::connect(&singleObject, &Object::signal0, &singleObject, &Object::slot0); - } else { - singleObject.connect(&singleObject, SIGNAL(signal0()), SLOT(slot0())); - } - - multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(slot0())); - // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal1())); - multiObject.connect(&multiObject, SIGNAL(signal1()), SLOT(slot1())); - // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal2())); - multiObject.connect(&multiObject, SIGNAL(signal2()), SLOT(slot2())); - // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal3())); - multiObject.connect(&multiObject, SIGNAL(signal3()), SLOT(slot3())); - // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal4())); - multiObject.connect(&multiObject, SIGNAL(signal4()), SLOT(slot4())); - // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal5())); - multiObject.connect(&multiObject, SIGNAL(signal5()), SLOT(slot5())); - // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal6())); - multiObject.connect(&multiObject, SIGNAL(signal6()), SLOT(slot6())); - // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal7())); - multiObject.connect(&multiObject, SIGNAL(signal7()), SLOT(slot7())); - // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal8())); - multiObject.connect(&multiObject, SIGNAL(signal8()), SLOT(slot8())); - // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal9())); - multiObject.connect(&multiObject, SIGNAL(signal9()), SLOT(slot9())); - - if (type == 0) { - QBENCHMARK { - singleObject.slot0(); - } - } else if (type == 1) { - QBENCHMARK { - singleObject.emitSignal0(); - } - } else if (type == 2) { - QBENCHMARK { - multiObject.emitSignal0(); - } - } else if (type == 3) { - QBENCHMARK { - singleObject.emitSignal1(); - } - } else if (type == 4 || type == 5) { - QBENCHMARK { - singleObject.emitSignal0(); - } - } -} - -void QObjectBenchmark::signal_many_receivers_data() -{ - QTest::addColumn("receiverCount"); - QTest::newRow("100 receivers") << 100; - QTest::newRow("1 000 receivers") << 1000; - QTest::newRow("10 000 receivers") << 10000; -} - -void QObjectBenchmark::signal_many_receivers() -{ - QFETCH(int, receiverCount); - Object sender; - std::vector receivers(receiverCount); - - for (Object &receiver : receivers) - QObject::connect(&sender, &Object::signal0, &receiver, &Object::slot0); - - QBENCHMARK { - sender.emitSignal0(); - } -} - -void QObjectBenchmark::qproperty_benchmark_data() -{ - QTest::addColumn("name"); - const QMetaObject *mo = &QTreeView::staticMetaObject; - for (int i = 0; i < mo->propertyCount(); ++i) { - QMetaProperty prop = mo->property(i); - if (prop.isWritable()) - QTest::newRow(prop.name()) << QByteArray(prop.name()); - } -} - -void QObjectBenchmark::qproperty_benchmark() -{ - QFETCH(QByteArray, name); - const char *p = name.constData(); - QTreeView obj; - QVariant v = obj.property(p); - QBENCHMARK { - obj.setProperty(p, v); - (void)obj.property(p); - } -} - -void QObjectBenchmark::dynamic_property_benchmark() -{ - QTreeView obj; - QBENCHMARK { - obj.setProperty("myProperty", 123); - (void)obj.property("myProperty"); - obj.setProperty("myOtherProperty", 123); - (void)obj.property("myOtherProperty"); - } -} - -void QObjectBenchmark::connect_disconnect_benchmark_data() -{ - QTest::addColumn("type"); - QTest::newRow("normalized signature") << 0; - QTest::newRow("unormalized signature") << 1; - QTest::newRow("function pointer") << 2; - QTest::newRow("normalized signature/handle") << 3; - QTest::newRow("unormalized signature/handle") << 4; - QTest::newRow("function pointer/handle") << 5; - QTest::newRow("functor/handle") << 6;} - -void QObjectBenchmark::connect_disconnect_benchmark() -{ - QFETCH(int, type); - switch (type) { - case 0: { - QTreeView obj; - QBENCHMARK { - QObject::connect (&obj, SIGNAL(viewportEntered()), &obj, SLOT(expandAll())); - QObject::disconnect(&obj, SIGNAL(viewportEntered()), &obj, SLOT(expandAll())); - } - } break; - case 1: { - QTreeView obj; - QBENCHMARK { - QObject::connect (&obj, SIGNAL(viewportEntered( )), &obj, SLOT(expandAll( ))); // sic: non-normalised - QObject::disconnect(&obj, SIGNAL(viewportEntered( )), &obj, SLOT(expandAll( ))); // sic: non-normalised - } - } break; - case 2: { - QTreeView obj; - QBENCHMARK { - QObject::connect (&obj, &QAbstractItemView::viewportEntered, &obj, &QTreeView::expandAll); - QObject::disconnect(&obj, &QAbstractItemView::viewportEntered, &obj, &QTreeView::expandAll); - } - } break; - case 3: { - QTreeView obj; - QBENCHMARK { - QObject::disconnect(QObject::connect(&obj, SIGNAL(viewportEntered()), &obj, SLOT(expandAll()))); - } - } break; - case 4: { - QTreeView obj; - QBENCHMARK { - QObject::disconnect(QObject::connect(&obj, SIGNAL(viewportEntered( )), &obj, SLOT(expandAll( )))); // sic: non-normalised - } - } break; - case 5: { - QTreeView obj; - QBENCHMARK { - QObject::disconnect(QObject::connect(&obj, &QAbstractItemView::viewportEntered, &obj, &QTreeView::expandAll)); - } - } break; - case 6: { - QTreeView obj; - Functor functor; - QBENCHMARK { - QObject::disconnect(QObject::connect(&obj, &QAbstractItemView::viewportEntered, functor)); - } - } break; - } -} - -void QObjectBenchmark::receiver_destroyed_benchmark() -{ - Object sender; - QBENCHMARK { - Object receiver; - QObject::connect(&sender, &Object::signal0, &receiver, &Object::slot0); - } -} - -QTEST_MAIN(QObjectBenchmark) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/kernel/qobject/tst_bench_qobject.cpp b/tests/benchmarks/corelib/kernel/qobject/tst_bench_qobject.cpp new file mode 100644 index 0000000000..0f57f2997a --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qobject/tst_bench_qobject.cpp @@ -0,0 +1,310 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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 "object.h" +#include +#include + +enum { + CreationDeletionBenckmarkConstant = 34567, + SignalsAndSlotsBenchmarkConstant = 456789 +}; + +class tst_QObject : public QObject +{ +Q_OBJECT +private slots: + void signal_slot_benchmark(); + void signal_slot_benchmark_data(); + void signal_many_receivers(); + void signal_many_receivers_data(); + void qproperty_benchmark_data(); + void qproperty_benchmark(); + void dynamic_property_benchmark(); + void connect_disconnect_benchmark_data(); + void connect_disconnect_benchmark(); + void receiver_destroyed_benchmark(); + + void stdAllocator(); +}; + +class QObjectUsingStandardAllocator : public QObject +{ + Q_OBJECT +public: + QObjectUsingStandardAllocator() + { + } +}; + +template +inline void allocator() +{ + // We need to allocate certain amount of objects otherwise the new implementation + // may re-use the previous allocation, hiding the somehow high cost of allocation. It + // also helps us to reduce the noise ratio, which is high for memory allocation. + // + // The check depends on memory allocation performance, which is quite non-deterministic. + // When a new memory is requested, the new operator, depending on implementation, is trying + // to re-use existing, already allocated for the process memory. If there is not enough, it + // asks OS to give more. Of course the first case is faster then the second. In the same + // time, from an application perspective the first is also more likely. + // + // As a result, depending on which use-case one wants to test, it may be recommended to run this + // test in separation from others, to "force" expensive code path in the memory allocation. + // + // The time based results are heavily affected by background noise. One really needs to + // prepare OS (no other tasks, CPU and RAM reservations) to run this test, or use + // instruction counting which seems to be less fragile. + + const int count = 256 * 1024; + + QScopedPointer objects[count]; + QBENCHMARK_ONCE { + for (int i = 0; i < count; ++i) + objects[i].reset(new T); + for (int i = 0; i < count; ++i) + objects[i].reset(); + } +} + +void tst_QObject::stdAllocator() +{ + allocator(); +} + +struct Functor { + void operator()(){} +}; + +void tst_QObject::signal_slot_benchmark_data() +{ + QTest::addColumn("type"); + QTest::newRow("simple function") << 0; + QTest::newRow("single signal/slot") << 1; + QTest::newRow("multi signal/slot") << 2; + QTest::newRow("unconnected signal") << 3; + QTest::newRow("single signal/ptr") << 4; + QTest::newRow("functor") << 5; +} + +void tst_QObject::signal_slot_benchmark() +{ + QFETCH(int, type); + + Object singleObject; + Object multiObject; + Functor functor; + singleObject.setObjectName("single"); + multiObject.setObjectName("multi"); + + if (type == 5) { + QObject::connect(&singleObject, &Object::signal0, functor); + } else if (type == 4) { + QObject::connect(&singleObject, &Object::signal0, &singleObject, &Object::slot0); + } else { + singleObject.connect(&singleObject, SIGNAL(signal0()), SLOT(slot0())); + } + + multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(slot0())); + // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal1())); + multiObject.connect(&multiObject, SIGNAL(signal1()), SLOT(slot1())); + // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal2())); + multiObject.connect(&multiObject, SIGNAL(signal2()), SLOT(slot2())); + // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal3())); + multiObject.connect(&multiObject, SIGNAL(signal3()), SLOT(slot3())); + // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal4())); + multiObject.connect(&multiObject, SIGNAL(signal4()), SLOT(slot4())); + // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal5())); + multiObject.connect(&multiObject, SIGNAL(signal5()), SLOT(slot5())); + // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal6())); + multiObject.connect(&multiObject, SIGNAL(signal6()), SLOT(slot6())); + // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal7())); + multiObject.connect(&multiObject, SIGNAL(signal7()), SLOT(slot7())); + // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal8())); + multiObject.connect(&multiObject, SIGNAL(signal8()), SLOT(slot8())); + // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal9())); + multiObject.connect(&multiObject, SIGNAL(signal9()), SLOT(slot9())); + + if (type == 0) { + QBENCHMARK { + singleObject.slot0(); + } + } else if (type == 1) { + QBENCHMARK { + singleObject.emitSignal0(); + } + } else if (type == 2) { + QBENCHMARK { + multiObject.emitSignal0(); + } + } else if (type == 3) { + QBENCHMARK { + singleObject.emitSignal1(); + } + } else if (type == 4 || type == 5) { + QBENCHMARK { + singleObject.emitSignal0(); + } + } +} + +void tst_QObject::signal_many_receivers_data() +{ + QTest::addColumn("receiverCount"); + QTest::newRow("100 receivers") << 100; + QTest::newRow("1 000 receivers") << 1000; + QTest::newRow("10 000 receivers") << 10000; +} + +void tst_QObject::signal_many_receivers() +{ + QFETCH(int, receiverCount); + Object sender; + std::vector receivers(receiverCount); + + for (Object &receiver : receivers) + QObject::connect(&sender, &Object::signal0, &receiver, &Object::slot0); + + QBENCHMARK { + sender.emitSignal0(); + } +} + +void tst_QObject::qproperty_benchmark_data() +{ + QTest::addColumn("name"); + const QMetaObject *mo = &QTreeView::staticMetaObject; + for (int i = 0; i < mo->propertyCount(); ++i) { + QMetaProperty prop = mo->property(i); + if (prop.isWritable()) + QTest::newRow(prop.name()) << QByteArray(prop.name()); + } +} + +void tst_QObject::qproperty_benchmark() +{ + QFETCH(QByteArray, name); + const char *p = name.constData(); + QTreeView obj; + QVariant v = obj.property(p); + QBENCHMARK { + obj.setProperty(p, v); + (void)obj.property(p); + } +} + +void tst_QObject::dynamic_property_benchmark() +{ + QTreeView obj; + QBENCHMARK { + obj.setProperty("myProperty", 123); + (void)obj.property("myProperty"); + obj.setProperty("myOtherProperty", 123); + (void)obj.property("myOtherProperty"); + } +} + +void tst_QObject::connect_disconnect_benchmark_data() +{ + QTest::addColumn("type"); + QTest::newRow("normalized signature") << 0; + QTest::newRow("unormalized signature") << 1; + QTest::newRow("function pointer") << 2; + QTest::newRow("normalized signature/handle") << 3; + QTest::newRow("unormalized signature/handle") << 4; + QTest::newRow("function pointer/handle") << 5; + QTest::newRow("functor/handle") << 6;} + +void tst_QObject::connect_disconnect_benchmark() +{ + QFETCH(int, type); + switch (type) { + case 0: { + QTreeView obj; + QBENCHMARK { + QObject::connect (&obj, SIGNAL(viewportEntered()), &obj, SLOT(expandAll())); + QObject::disconnect(&obj, SIGNAL(viewportEntered()), &obj, SLOT(expandAll())); + } + } break; + case 1: { + QTreeView obj; + QBENCHMARK { + QObject::connect (&obj, SIGNAL(viewportEntered( )), &obj, SLOT(expandAll( ))); // sic: non-normalised + QObject::disconnect(&obj, SIGNAL(viewportEntered( )), &obj, SLOT(expandAll( ))); // sic: non-normalised + } + } break; + case 2: { + QTreeView obj; + QBENCHMARK { + QObject::connect (&obj, &QAbstractItemView::viewportEntered, &obj, &QTreeView::expandAll); + QObject::disconnect(&obj, &QAbstractItemView::viewportEntered, &obj, &QTreeView::expandAll); + } + } break; + case 3: { + QTreeView obj; + QBENCHMARK { + QObject::disconnect(QObject::connect(&obj, SIGNAL(viewportEntered()), &obj, SLOT(expandAll()))); + } + } break; + case 4: { + QTreeView obj; + QBENCHMARK { + QObject::disconnect(QObject::connect(&obj, SIGNAL(viewportEntered( )), &obj, SLOT(expandAll( )))); // sic: non-normalised + } + } break; + case 5: { + QTreeView obj; + QBENCHMARK { + QObject::disconnect(QObject::connect(&obj, &QAbstractItemView::viewportEntered, &obj, &QTreeView::expandAll)); + } + } break; + case 6: { + QTreeView obj; + Functor functor; + QBENCHMARK { + QObject::disconnect(QObject::connect(&obj, &QAbstractItemView::viewportEntered, functor)); + } + } break; + } +} + +void tst_QObject::receiver_destroyed_benchmark() +{ + Object sender; + QBENCHMARK { + Object receiver; + QObject::connect(&sender, &Object::signal0, &receiver, &Object::slot0); + } +} + +QTEST_MAIN(tst_QObject) + +#include "tst_bench_qobject.moc" diff --git a/tests/benchmarks/corelib/kernel/qproperty/CMakeLists.txt b/tests/benchmarks/corelib/kernel/qproperty/CMakeLists.txt index d6fc1c5a14..42345e6492 100644 --- a/tests/benchmarks/corelib/kernel/qproperty/CMakeLists.txt +++ b/tests/benchmarks/corelib/kernel/qproperty/CMakeLists.txt @@ -1,6 +1,6 @@ qt_internal_add_benchmark(tst_bench_qproperty SOURCES - main.cpp + tst_bench_qproperty.cpp propertytester.h PUBLIC_LIBRARIES Qt::Core diff --git a/tests/benchmarks/corelib/kernel/qproperty/main.cpp b/tests/benchmarks/corelib/kernel/qproperty/main.cpp deleted file mode 100644 index 5d6db35d2b..0000000000 --- a/tests/benchmarks/corelib/kernel/qproperty/main.cpp +++ /dev/null @@ -1,231 +0,0 @@ -/**************************************************************************** -** -** 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/tst_bench_qproperty.cpp b/tests/benchmarks/corelib/kernel/qproperty/tst_bench_qproperty.cpp new file mode 100644 index 0000000000..ad62ad8075 --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qproperty/tst_bench_qproperty.cpp @@ -0,0 +1,232 @@ +/**************************************************************************** +** +** 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 tst_QProperty : 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 tst_QProperty::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 tst_QProperty::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 tst_QProperty::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 tst_QProperty::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 tst_QProperty::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 tst_QProperty::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 tst_QProperty::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 tst_QProperty::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 tst_QProperty::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 tst_QProperty::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 tst_QProperty::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 tst_QProperty::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(tst_QProperty) + +#include "tst_bench_qproperty.moc" diff --git a/tests/benchmarks/corelib/kernel/qvariant/CMakeLists.txt b/tests/benchmarks/corelib/kernel/qvariant/CMakeLists.txt index 418fd1da9f..83e7269ff0 100644 --- a/tests/benchmarks/corelib/kernel/qvariant/CMakeLists.txt +++ b/tests/benchmarks/corelib/kernel/qvariant/CMakeLists.txt @@ -1,12 +1,10 @@ -# Generated from qvariant.pro. - ##################################################################### ## tst_bench_qvariant Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qvariant SOURCES - tst_qvariant.cpp + tst_bench_qvariant.cpp PUBLIC_LIBRARIES Qt::Gui Qt::Test diff --git a/tests/benchmarks/corelib/kernel/qvariant/tst_bench_qvariant.cpp b/tests/benchmarks/corelib/kernel/qvariant/tst_bench_qvariant.cpp new file mode 100644 index 0000000000..1e35cf85f9 --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qvariant/tst_bench_qvariant.cpp @@ -0,0 +1,381 @@ +/**************************************************************************** +** +** Copyright (C) 2016 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 +#ifdef QT_GUI_LIB +# include +#endif +#include + +#define ITERATION_COUNT 1e5 + +class tst_QVariant : public QObject +{ + Q_OBJECT + +public: + enum ABenchmarkEnum { + FirstEnumValue, + SecondEnumValue, + ThirdEnumValue + }; + Q_ENUM(ABenchmarkEnum) + +private slots: + void testBound(); + + void doubleVariantCreation(); + void floatVariantCreation(); + void rectVariantCreation(); + void stringVariantCreation(); +#ifdef QT_GUI_LIB + void pixmapVariantCreation(); +#endif + void stringListVariantCreation(); + void bigClassVariantCreation(); + void smallClassVariantCreation(); + void enumVariantCreation(); + + void doubleVariantSetValue(); + void floatVariantSetValue(); + void rectVariantSetValue(); + void stringVariantSetValue(); + void stringListVariantSetValue(); + void bigClassVariantSetValue(); + void smallClassVariantSetValue(); + void enumVariantSetValue(); + + void doubleVariantAssignment(); + void floatVariantAssignment(); + void rectVariantAssignment(); + void stringVariantAssignment(); + void stringListVariantAssignment(); + + void doubleVariantValue(); + void floatVariantValue(); + void rectVariantValue(); + void stringVariantValue(); + + void createCoreType_data(); + void createCoreType(); + void createCoreTypeCopy_data(); + void createCoreTypeCopy(); +}; + +struct BigClass +{ + double n,i,e,r,o,b; +}; +static_assert(sizeof(BigClass) > sizeof(QVariant::Private::MaxInternalSize)); +QT_BEGIN_NAMESPACE +Q_DECLARE_TYPEINFO(BigClass, Q_RELOCATABLE_TYPE); +QT_END_NAMESPACE +Q_DECLARE_METATYPE(BigClass); + +struct SmallClass +{ + char s; +}; +static_assert(sizeof(SmallClass) <= sizeof(QVariant::Private::MaxInternalSize)); +QT_BEGIN_NAMESPACE +Q_DECLARE_TYPEINFO(SmallClass, Q_RELOCATABLE_TYPE); +QT_END_NAMESPACE +Q_DECLARE_METATYPE(SmallClass); + +void tst_QVariant::testBound() +{ + qreal d = qreal(.5); + QBENCHMARK { + for(int i = 0; i < ITERATION_COUNT; ++i) { + d = qBound(0, d, 1); + } + } +} + +template +static void variantCreation(T val) +{ + QBENCHMARK { + for(int i = 0; i < ITERATION_COUNT; ++i) { + QVariant v(val); + } + } +} + +template <> +void variantCreation(BigClass val) +{ + QBENCHMARK { + for (int i = 0; i < ITERATION_COUNT; ++i) { + QVariant::fromValue(val); + } + } +} + +template <> +void variantCreation(SmallClass val) +{ + QBENCHMARK { + for (int i = 0; i < ITERATION_COUNT; ++i) { + QVariant::fromValue(val); + } + } +} + +template <> +void variantCreation(tst_QVariant::ABenchmarkEnum val) +{ + QBENCHMARK { + for (int i = 0; i < ITERATION_COUNT; ++i) { + QVariant::fromValue(val); + } + } +} + + +void tst_QVariant::doubleVariantCreation() +{ + variantCreation(0.0); +} + +void tst_QVariant::floatVariantCreation() +{ + variantCreation(0.0f); +} + +void tst_QVariant::rectVariantCreation() +{ + variantCreation(QRect(1, 2, 3, 4)); +} + +void tst_QVariant::stringVariantCreation() +{ + variantCreation(QString()); +} + +#ifdef QT_GUI_LIB +void tst_QVariant::pixmapVariantCreation() +{ + variantCreation(QPixmap()); +} +#endif + +void tst_QVariant::stringListVariantCreation() +{ + variantCreation(QStringList()); +} + +void tst_QVariant::bigClassVariantCreation() +{ + variantCreation(BigClass()); +} + +void tst_QVariant::smallClassVariantCreation() +{ + variantCreation(SmallClass()); +} + +void tst_QVariant::enumVariantCreation() +{ + variantCreation(FirstEnumValue); +} + + +template +static void variantSetValue(T d) +{ + QVariant v; + QBENCHMARK { + for(int i = 0; i < ITERATION_COUNT; ++i) { + v.setValue(d); + } + } +} + +void tst_QVariant::doubleVariantSetValue() +{ + variantSetValue(0.0); +} + +void tst_QVariant::floatVariantSetValue() +{ + variantSetValue(0.0f); +} + +void tst_QVariant::rectVariantSetValue() +{ + variantSetValue(QRect()); +} + +void tst_QVariant::stringVariantSetValue() +{ + variantSetValue(QString()); +} + +void tst_QVariant::stringListVariantSetValue() +{ + variantSetValue(QStringList()); +} + +void tst_QVariant::bigClassVariantSetValue() +{ + variantSetValue(BigClass()); +} + +void tst_QVariant::smallClassVariantSetValue() +{ + variantSetValue(SmallClass()); +} + +void tst_QVariant::enumVariantSetValue() +{ + variantSetValue(FirstEnumValue); +} + +template +static void variantAssignment(T d) +{ + QVariant v; + QBENCHMARK { + for(int i = 0; i < ITERATION_COUNT; ++i) { + v = d; + } + } +} + +void tst_QVariant::doubleVariantAssignment() +{ + variantAssignment(0.0); +} + +void tst_QVariant::floatVariantAssignment() +{ + variantAssignment(0.0f); +} + +void tst_QVariant::rectVariantAssignment() +{ + variantAssignment(QRect()); +} + +void tst_QVariant::stringVariantAssignment() +{ + variantAssignment(QString()); +} + +void tst_QVariant::stringListVariantAssignment() +{ + variantAssignment(QStringList()); +} + +void tst_QVariant::doubleVariantValue() +{ + QVariant v(0.0); + QBENCHMARK { + for(int i = 0; i < ITERATION_COUNT; ++i) { + v.toDouble(); + } + } +} + +void tst_QVariant::floatVariantValue() +{ + QVariant v(0.0f); + QBENCHMARK { + for(int i = 0; i < ITERATION_COUNT; ++i) { + v.toFloat(); + } + } +} + +void tst_QVariant::rectVariantValue() +{ + QVariant v(QRect(1,2,3,4)); + QBENCHMARK { + for(int i = 0; i < ITERATION_COUNT; ++i) { + v.toRect(); + } + } +} + +void tst_QVariant::stringVariantValue() +{ + QVariant v = QString(); + QBENCHMARK { + for(int i = 0; i < ITERATION_COUNT; ++i) { + v.toString(); + } + } +} + +void tst_QVariant::createCoreType_data() +{ + QTest::addColumn("typeId"); + for (int i = QMetaType::FirstCoreType; i <= QMetaType::LastCoreType; ++i) { + if (QMetaType metaType(i); metaType.isValid()) // QMetaType(27) does not exist + QTest::newRow(metaType.name()) << i; + } +} + +// Tests how fast a Qt core type can be default-constructed by a +// QVariant. The purpose of this benchmark is to measure the overhead +// of creating (and destroying) a QVariant compared to creating the +// type directly. +void tst_QVariant::createCoreType() +{ + QFETCH(int, typeId); + QBENCHMARK { + for (int i = 0; i < ITERATION_COUNT; ++i) + QVariant(QMetaType(typeId)); + } +} + +void tst_QVariant::createCoreTypeCopy_data() +{ + createCoreType_data(); +} + +// Tests how fast a Qt core type can be copy-constructed by a +// QVariant. The purpose of this benchmark is to measure the overhead +// of creating (and destroying) a QVariant compared to creating the +// type directly. +void tst_QVariant::createCoreTypeCopy() +{ + QFETCH(int, typeId); + QMetaType metaType(typeId); + QVariant other(metaType); + const void *copy = other.constData(); + QBENCHMARK { + for (int i = 0; i < ITERATION_COUNT; ++i) + QVariant(metaType, copy); + } +} + +QTEST_MAIN(tst_QVariant) + +#include "tst_bench_qvariant.moc" diff --git a/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp deleted file mode 100644 index f2618f7813..0000000000 --- a/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp +++ /dev/null @@ -1,381 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 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 -#ifdef QT_GUI_LIB -# include -#endif -#include - -#define ITERATION_COUNT 1e5 - -class tst_qvariant : public QObject -{ - Q_OBJECT - -public: - enum ABenchmarkEnum { - FirstEnumValue, - SecondEnumValue, - ThirdEnumValue - }; - Q_ENUM(ABenchmarkEnum) - -private slots: - void testBound(); - - void doubleVariantCreation(); - void floatVariantCreation(); - void rectVariantCreation(); - void stringVariantCreation(); -#ifdef QT_GUI_LIB - void pixmapVariantCreation(); -#endif - void stringListVariantCreation(); - void bigClassVariantCreation(); - void smallClassVariantCreation(); - void enumVariantCreation(); - - void doubleVariantSetValue(); - void floatVariantSetValue(); - void rectVariantSetValue(); - void stringVariantSetValue(); - void stringListVariantSetValue(); - void bigClassVariantSetValue(); - void smallClassVariantSetValue(); - void enumVariantSetValue(); - - void doubleVariantAssignment(); - void floatVariantAssignment(); - void rectVariantAssignment(); - void stringVariantAssignment(); - void stringListVariantAssignment(); - - void doubleVariantValue(); - void floatVariantValue(); - void rectVariantValue(); - void stringVariantValue(); - - void createCoreType_data(); - void createCoreType(); - void createCoreTypeCopy_data(); - void createCoreTypeCopy(); -}; - -struct BigClass -{ - double n,i,e,r,o,b; -}; -static_assert(sizeof(BigClass) > sizeof(QVariant::Private::MaxInternalSize)); -QT_BEGIN_NAMESPACE -Q_DECLARE_TYPEINFO(BigClass, Q_RELOCATABLE_TYPE); -QT_END_NAMESPACE -Q_DECLARE_METATYPE(BigClass); - -struct SmallClass -{ - char s; -}; -static_assert(sizeof(SmallClass) <= sizeof(QVariant::Private::MaxInternalSize)); -QT_BEGIN_NAMESPACE -Q_DECLARE_TYPEINFO(SmallClass, Q_RELOCATABLE_TYPE); -QT_END_NAMESPACE -Q_DECLARE_METATYPE(SmallClass); - -void tst_qvariant::testBound() -{ - qreal d = qreal(.5); - QBENCHMARK { - for(int i = 0; i < ITERATION_COUNT; ++i) { - d = qBound(0, d, 1); - } - } -} - -template -static void variantCreation(T val) -{ - QBENCHMARK { - for(int i = 0; i < ITERATION_COUNT; ++i) { - QVariant v(val); - } - } -} - -template <> -void variantCreation(BigClass val) -{ - QBENCHMARK { - for (int i = 0; i < ITERATION_COUNT; ++i) { - QVariant::fromValue(val); - } - } -} - -template <> -void variantCreation(SmallClass val) -{ - QBENCHMARK { - for (int i = 0; i < ITERATION_COUNT; ++i) { - QVariant::fromValue(val); - } - } -} - -template <> -void variantCreation(tst_qvariant::ABenchmarkEnum val) -{ - QBENCHMARK { - for (int i = 0; i < ITERATION_COUNT; ++i) { - QVariant::fromValue(val); - } - } -} - - -void tst_qvariant::doubleVariantCreation() -{ - variantCreation(0.0); -} - -void tst_qvariant::floatVariantCreation() -{ - variantCreation(0.0f); -} - -void tst_qvariant::rectVariantCreation() -{ - variantCreation(QRect(1, 2, 3, 4)); -} - -void tst_qvariant::stringVariantCreation() -{ - variantCreation(QString()); -} - -#ifdef QT_GUI_LIB -void tst_qvariant::pixmapVariantCreation() -{ - variantCreation(QPixmap()); -} -#endif - -void tst_qvariant::stringListVariantCreation() -{ - variantCreation(QStringList()); -} - -void tst_qvariant::bigClassVariantCreation() -{ - variantCreation(BigClass()); -} - -void tst_qvariant::smallClassVariantCreation() -{ - variantCreation(SmallClass()); -} - -void tst_qvariant::enumVariantCreation() -{ - variantCreation(FirstEnumValue); -} - - -template -static void variantSetValue(T d) -{ - QVariant v; - QBENCHMARK { - for(int i = 0; i < ITERATION_COUNT; ++i) { - v.setValue(d); - } - } -} - -void tst_qvariant::doubleVariantSetValue() -{ - variantSetValue(0.0); -} - -void tst_qvariant::floatVariantSetValue() -{ - variantSetValue(0.0f); -} - -void tst_qvariant::rectVariantSetValue() -{ - variantSetValue(QRect()); -} - -void tst_qvariant::stringVariantSetValue() -{ - variantSetValue(QString()); -} - -void tst_qvariant::stringListVariantSetValue() -{ - variantSetValue(QStringList()); -} - -void tst_qvariant::bigClassVariantSetValue() -{ - variantSetValue(BigClass()); -} - -void tst_qvariant::smallClassVariantSetValue() -{ - variantSetValue(SmallClass()); -} - -void tst_qvariant::enumVariantSetValue() -{ - variantSetValue(FirstEnumValue); -} - -template -static void variantAssignment(T d) -{ - QVariant v; - QBENCHMARK { - for(int i = 0; i < ITERATION_COUNT; ++i) { - v = d; - } - } -} - -void tst_qvariant::doubleVariantAssignment() -{ - variantAssignment(0.0); -} - -void tst_qvariant::floatVariantAssignment() -{ - variantAssignment(0.0f); -} - -void tst_qvariant::rectVariantAssignment() -{ - variantAssignment(QRect()); -} - -void tst_qvariant::stringVariantAssignment() -{ - variantAssignment(QString()); -} - -void tst_qvariant::stringListVariantAssignment() -{ - variantAssignment(QStringList()); -} - -void tst_qvariant::doubleVariantValue() -{ - QVariant v(0.0); - QBENCHMARK { - for(int i = 0; i < ITERATION_COUNT; ++i) { - v.toDouble(); - } - } -} - -void tst_qvariant::floatVariantValue() -{ - QVariant v(0.0f); - QBENCHMARK { - for(int i = 0; i < ITERATION_COUNT; ++i) { - v.toFloat(); - } - } -} - -void tst_qvariant::rectVariantValue() -{ - QVariant v(QRect(1,2,3,4)); - QBENCHMARK { - for(int i = 0; i < ITERATION_COUNT; ++i) { - v.toRect(); - } - } -} - -void tst_qvariant::stringVariantValue() -{ - QVariant v = QString(); - QBENCHMARK { - for(int i = 0; i < ITERATION_COUNT; ++i) { - v.toString(); - } - } -} - -void tst_qvariant::createCoreType_data() -{ - QTest::addColumn("typeId"); - for (int i = QMetaType::FirstCoreType; i <= QMetaType::LastCoreType; ++i) { - if (QMetaType metaType(i); metaType.isValid()) // QMetaType(27) does not exist - QTest::newRow(metaType.name()) << i; - } -} - -// Tests how fast a Qt core type can be default-constructed by a -// QVariant. The purpose of this benchmark is to measure the overhead -// of creating (and destroying) a QVariant compared to creating the -// type directly. -void tst_qvariant::createCoreType() -{ - QFETCH(int, typeId); - QBENCHMARK { - for (int i = 0; i < ITERATION_COUNT; ++i) - QVariant(QMetaType(typeId)); - } -} - -void tst_qvariant::createCoreTypeCopy_data() -{ - createCoreType_data(); -} - -// Tests how fast a Qt core type can be copy-constructed by a -// QVariant. The purpose of this benchmark is to measure the overhead -// of creating (and destroying) a QVariant compared to creating the -// type directly. -void tst_qvariant::createCoreTypeCopy() -{ - QFETCH(int, typeId); - QMetaType metaType(typeId); - QVariant other(metaType); - const void *copy = other.constData(); - QBENCHMARK { - for (int i = 0; i < ITERATION_COUNT; ++i) - QVariant(metaType, copy); - } -} - -QTEST_MAIN(tst_qvariant) - -#include "tst_qvariant.moc" diff --git a/tests/benchmarks/corelib/kernel/qwineventnotifier/CMakeLists.txt b/tests/benchmarks/corelib/kernel/qwineventnotifier/CMakeLists.txt index a581b1eaef..046564ba8e 100644 --- a/tests/benchmarks/corelib/kernel/qwineventnotifier/CMakeLists.txt +++ b/tests/benchmarks/corelib/kernel/qwineventnotifier/CMakeLists.txt @@ -1,15 +1,10 @@ -# Generated from qwineventnotifier.pro. - ##################################################################### ## tst_bench_qwineventnotifier Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qwineventnotifier SOURCES - main.cpp + tst_bench_qwineventnotifier.cpp PUBLIC_LIBRARIES Qt::Test ) - -#### Keys ignored in scope 1:.:.:qwineventnotifier.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/kernel/qwineventnotifier/main.cpp b/tests/benchmarks/corelib/kernel/qwineventnotifier/main.cpp deleted file mode 100644 index 926ed5acdb..0000000000 --- a/tests/benchmarks/corelib/kernel/qwineventnotifier/main.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2020 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 -#include -#include -#include - -class QWinEventNotifierBenchmark : public QObject -{ - Q_OBJECT - -private slots: - void waves_data(); - void waves(); -}; - -class EventsFactory : public QObject -{ - Q_OBJECT - -public: - explicit EventsFactory(int waves, int notifiers, int iterations) - : numberOfWaves(waves), numberOfNotifiers(notifiers), - numberOfIterations(iterations) - { - events.resize(notifiers); - for (int i = 0; i < notifiers; ++i) { - events[i] = CreateEvent(NULL, TRUE, FALSE, NULL); - QVERIFY(events[i] != NULL); - QWinEventNotifier *notifier = new QWinEventNotifier(events[i], this); - Q_CHECK_PTR(notifier); - - connect(notifier, &QWinEventNotifier::activated, [i, this]() { - ResetEvent(this->events[i]); - if (--this->numberOfIterations == 0) - this->eventLoop.quit(); - else - SetEvent(this->events[(i + 1) % this->numberOfNotifiers]); - }); - - connect(this, &EventsFactory::stop, [notifier]() { - notifier->setEnabled(false); - }); - } - } - virtual ~EventsFactory() - { - for (auto event : events) - CloseHandle(event); - } - - void run() - { - Q_ASSERT(numberOfWaves != 0); - - int offset = 0; - for (int i = 0; i < numberOfWaves; ++i) { - SetEvent(events[offset]); - offset += qMax(1, numberOfNotifiers / numberOfWaves); - offset %= numberOfNotifiers; - } - eventLoop.exec(); - } - -signals: - void stop(); - -protected: - QVector events; - QEventLoop eventLoop; - int numberOfWaves; - int numberOfNotifiers; - int numberOfIterations; -}; - -void QWinEventNotifierBenchmark::waves_data() -{ - QTest::addColumn("waves"); - QTest::addColumn("notifiers"); - for (int waves : {1, 3, 10}) { - for (int notifiers : {10, 100, 1000}) - QTest::addRow("waves: %d, notifiers: %d", waves, notifiers) << waves << notifiers; - } -} - -void QWinEventNotifierBenchmark::waves() -{ - QFETCH(int, waves); - QFETCH(int, notifiers); - - const int iterations = 100000; - - EventsFactory factory(waves, notifiers, iterations); - - QElapsedTimer timer; - timer.start(); - - factory.run(); - - qDebug("Elapsed time: %.1f s", timer.elapsed() / 1000.0); - - emit factory.stop(); -} - -QTEST_MAIN(QWinEventNotifierBenchmark) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/kernel/qwineventnotifier/tst_bench_qwineventnotifier.cpp b/tests/benchmarks/corelib/kernel/qwineventnotifier/tst_bench_qwineventnotifier.cpp new file mode 100644 index 0000000000..33f82731ca --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qwineventnotifier/tst_bench_qwineventnotifier.cpp @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** Copyright (C) 2020 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 +#include +#include +#include + +class tst_QWinEventNotifier : public QObject +{ + Q_OBJECT + +private slots: + void waves_data(); + void waves(); +}; + +class EventsFactory : public QObject +{ + Q_OBJECT + +public: + explicit EventsFactory(int waves, int notifiers, int iterations) + : numberOfWaves(waves), numberOfNotifiers(notifiers), + numberOfIterations(iterations) + { + events.resize(notifiers); + for (int i = 0; i < notifiers; ++i) { + events[i] = CreateEvent(NULL, TRUE, FALSE, NULL); + QVERIFY(events[i] != NULL); + QWinEventNotifier *notifier = new QWinEventNotifier(events[i], this); + Q_CHECK_PTR(notifier); + + connect(notifier, &QWinEventNotifier::activated, [i, this]() { + ResetEvent(this->events[i]); + if (--this->numberOfIterations == 0) + this->eventLoop.quit(); + else + SetEvent(this->events[(i + 1) % this->numberOfNotifiers]); + }); + + connect(this, &EventsFactory::stop, [notifier]() { + notifier->setEnabled(false); + }); + } + } + virtual ~EventsFactory() + { + for (auto event : events) + CloseHandle(event); + } + + void run() + { + Q_ASSERT(numberOfWaves != 0); + + int offset = 0; + for (int i = 0; i < numberOfWaves; ++i) { + SetEvent(events[offset]); + offset += qMax(1, numberOfNotifiers / numberOfWaves); + offset %= numberOfNotifiers; + } + eventLoop.exec(); + } + +signals: + void stop(); + +protected: + QVector events; + QEventLoop eventLoop; + int numberOfWaves; + int numberOfNotifiers; + int numberOfIterations; +}; + +void tst_QWinEventNotifier::waves_data() +{ + QTest::addColumn("waves"); + QTest::addColumn("notifiers"); + for (int waves : {1, 3, 10}) { + for (int notifiers : {10, 100, 1000}) + QTest::addRow("waves: %d, notifiers: %d", waves, notifiers) << waves << notifiers; + } +} + +void tst_QWinEventNotifier::waves() +{ + QFETCH(int, waves); + QFETCH(int, notifiers); + + const int iterations = 100000; + + EventsFactory factory(waves, notifiers, iterations); + + QElapsedTimer timer; + timer.start(); + + factory.run(); + + qDebug("Elapsed time: %.1f s", timer.elapsed() / 1000.0); + + emit factory.stop(); +} + +QTEST_MAIN(tst_QWinEventNotifier) + +#include "tst_bench_qwineventnotifier.moc" -- cgit v1.2.3