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 --- tests/benchmarks/corelib/io/CMakeLists.txt | 7 +- .../corelib/io/qdir/10000/CMakeLists.txt | 7 +- .../corelib/io/qdir/10000/bench_qdir_10000.cpp | 198 ------- .../corelib/io/qdir/10000/tst_bench_qdir_10000.cpp | 211 ++++++++ tests/benchmarks/corelib/io/qdir/CMakeLists.txt | 3 +- .../benchmarks/corelib/io/qdir/tree/CMakeLists.txt | 18 +- .../corelib/io/qdir/tree/bench_qdir_tree.cpp | 225 -------- .../corelib/io/qdir/tree/bench_qdir_tree.qrc | 5 - .../corelib/io/qdir/tree/tst_bench_qdir_tree.cpp | 226 ++++++++ .../corelib/io/qdir/tree/tst_bench_qdir_tree.qrc | 5 + .../corelib/io/qdiriterator/CMakeLists.txt | 4 +- tests/benchmarks/corelib/io/qdiriterator/main.cpp | 262 ---------- .../io/qdiriterator/tst_bench_qdiriterator.cpp | 262 ++++++++++ .../benchmarks/corelib/io/qfileinfo/CMakeLists.txt | 7 +- tests/benchmarks/corelib/io/qfileinfo/main.cpp | 114 ---- .../corelib/io/qfileinfo/tst_bench_qfileinfo.cpp | 102 ++++ .../benchmarks/corelib/io/qiodevice/CMakeLists.txt | 7 +- tests/benchmarks/corelib/io/qiodevice/main.cpp | 124 ----- .../corelib/io/qiodevice/tst_bench_qiodevice.cpp | 123 +++++ .../corelib/io/qprocess/test/CMakeLists.txt | 2 - .../io/qprocess/testProcessLoopback/CMakeLists.txt | 2 +- .../io/qprocess/testProcessLoopback/loopback.cpp | 44 ++ .../io/qprocess/testProcessLoopback/main.cpp | 44 -- .../corelib/io/qtemporaryfile/CMakeLists.txt | 7 +- .../benchmarks/corelib/io/qtemporaryfile/main.cpp | 90 ---- .../io/qtemporaryfile/tst_bench_qtemporaryfile.cpp | 89 ++++ .../corelib/io/qtextstream/CMakeLists.txt | 7 +- tests/benchmarks/corelib/io/qtextstream/main.cpp | 120 ----- .../io/qtextstream/tst_bench_qtextstream.cpp | 120 +++++ tests/benchmarks/corelib/io/qurl/CMakeLists.txt | 11 +- tests/benchmarks/corelib/io/qurl/main.cpp | 208 -------- .../benchmarks/corelib/io/qurl/tst_bench_qurl.cpp | 210 ++++++++ .../qsortfilterproxymodel/CMakeLists.txt | 2 +- .../tst_bench_qsortfilterproxymodel.cpp | 123 +++++ .../tst_qsortfilterproxymodel.cpp | 123 ----- .../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 +++++ .../corelib/mimetypes/qmimedatabase/CMakeLists.txt | 4 +- .../corelib/mimetypes/qmimedatabase/main.cpp | 86 --- .../qmimedatabase/tst_bench_qmimedatabase.cpp | 87 ++++ .../benchmarks/corelib/plugin/quuid/CMakeLists.txt | 7 +- .../corelib/plugin/quuid/tst_bench_quuid.cpp | 197 +++++++ .../benchmarks/corelib/plugin/quuid/tst_quuid.cpp | 200 ------- .../corelib/text/qbytearray/CMakeLists.txt | 8 +- tests/benchmarks/corelib/text/qbytearray/main.cpp | 384 -------------- .../text/qbytearray/tst_bench_qbytearray.cpp | 383 ++++++++++++++ tests/benchmarks/corelib/text/qchar/CMakeLists.txt | 4 +- tests/benchmarks/corelib/text/qchar/main.cpp | 136 ----- .../corelib/text/qchar/tst_bench_qchar.cpp | 136 +++++ .../benchmarks/corelib/text/qlocale/CMakeLists.txt | 4 +- tests/benchmarks/corelib/text/qlocale/main.cpp | 397 -------------- .../corelib/text/qlocale/tst_bench_qlocale.cpp | 397 ++++++++++++++ .../corelib/text/qstringbuilder/CMakeLists.txt | 8 +- .../corelib/text/qstringbuilder/main.cpp | 415 --------------- .../qstringbuilder/tst_bench_qstringbuilder.cpp | 415 +++++++++++++++ .../corelib/text/qstringlist/CMakeLists.txt | 4 +- tests/benchmarks/corelib/text/qstringlist/main.cpp | 240 --------- .../text/qstringlist/tst_bench_qstringlist.cpp | 240 +++++++++ .../corelib/text/qstringtokenizer/CMakeLists.txt | 2 +- .../corelib/text/qstringtokenizer/main.cpp | 145 ------ .../tst_bench_qstringtokenizer.cpp | 145 ++++++ .../corelib/thread/qfuture/CMakeLists.txt | 2 +- .../corelib/thread/qfuture/tst_bench_qfuture.cpp | 321 ++++++++++++ .../corelib/thread/qfuture/tst_qfuture.cpp | 320 ------------ .../corelib/thread/qmutex/CMakeLists.txt | 7 +- .../corelib/thread/qmutex/tst_bench_qmutex.cpp | 454 ++++++++++++++++ .../corelib/thread/qmutex/tst_qmutex.cpp | 453 ---------------- .../corelib/thread/qreadwritelock/CMakeLists.txt | 7 +- .../qreadwritelock/tst_bench_qreadwritelock.cpp | 259 ++++++++++ .../thread/qreadwritelock/tst_qreadwritelock.cpp | 259 ---------- .../corelib/thread/qthreadpool/CMakeLists.txt | 7 +- .../thread/qthreadpool/tst_bench_qthreadpool.cpp | 80 +++ .../corelib/thread/qthreadpool/tst_qthreadpool.cpp | 79 --- .../corelib/thread/qthreadstorage/CMakeLists.txt | 7 +- .../qthreadstorage/tst_bench_qthreadstorage.cpp | 109 ++++ .../thread/qthreadstorage/tst_qthreadstorage.cpp | 109 ---- .../corelib/thread/qwaitcondition/CMakeLists.txt | 7 +- .../qwaitcondition/tst_bench_qwaitcondition.cpp | 129 +++++ .../thread/qwaitcondition/tst_qwaitcondition.cpp | 129 ----- .../corelib/time/qdatetime/CMakeLists.txt | 4 +- tests/benchmarks/corelib/time/qdatetime/main.cpp | 574 --------------------- .../corelib/time/qdatetime/tst_bench_qdatetime.cpp | 574 +++++++++++++++++++++ .../corelib/time/qtimezone/CMakeLists.txt | 4 +- tests/benchmarks/corelib/time/qtimezone/main.cpp | 166 ------ .../corelib/time/qtimezone/tst_bench_qtimezone.cpp | 166 ++++++ tests/benchmarks/corelib/tools/CMakeLists.txt | 4 +- .../tools/containers-associative/CMakeLists.txt | 11 +- .../corelib/tools/containers-associative/main.cpp | 130 ----- .../tst_bench_containers_associative.cpp | 131 +++++ .../tools/containers-sequential/CMakeLists.txt | 9 +- .../corelib/tools/containers-sequential/main.cpp | 247 --------- .../tst_bench_containers_sequential.cpp | 248 +++++++++ .../corelib/tools/qcontiguouscache/CMakeLists.txt | 4 +- .../corelib/tools/qcontiguouscache/main.cpp | 179 ------- .../tst_bench_qcontiguouscache.cpp | 179 +++++++ .../tools/qcryptographichash/CMakeLists.txt | 4 +- .../corelib/tools/qcryptographichash/main.cpp | 188 ------- .../tst_bench_qcryptographichash.cpp | 188 +++++++ .../benchmarks/corelib/tools/qhash/CMakeLists.txt | 8 +- tests/benchmarks/corelib/tools/qhash/main.cpp | 173 ------- tests/benchmarks/corelib/tools/qhash/main.h | 61 --- tests/benchmarks/corelib/tools/qhash/outofline.cpp | 2 +- .../corelib/tools/qhash/tst_bench_qhash.cpp | 174 +++++++ .../corelib/tools/qhash/tst_bench_qhash.h | 61 +++ .../benchmarks/corelib/tools/qlist/CMakeLists.txt | 4 +- tests/benchmarks/corelib/tools/qlist/main.cpp | 501 ------------------ .../corelib/tools/qlist/tst_bench_qlist.cpp | 501 ++++++++++++++++++ .../benchmarks/corelib/tools/qrect/CMakeLists.txt | 7 +- tests/benchmarks/corelib/tools/qrect/main.cpp | 316 ------------ .../corelib/tools/qrect/tst_bench_qrect.cpp | 316 ++++++++++++ .../corelib/tools/qringbuffer/CMakeLists.txt | 7 +- .../benchmarks/corelib/tools/qringbuffer/main.cpp | 71 --- .../tools/qringbuffer/tst_bench_qringbuffer.cpp | 71 +++ tests/benchmarks/corelib/tools/qset/CMakeLists.txt | 8 +- tests/benchmarks/corelib/tools/qset/main.cpp | 128 ----- .../corelib/tools/qset/tst_bench_qset.cpp | 128 +++++ .../benchmarks/corelib/tools/qstack/CMakeLists.txt | 8 +- tests/benchmarks/corelib/tools/qstack/main.cpp | 84 --- .../corelib/tools/qstack/tst_bench_qstack.cpp | 84 +++ 141 files changed, 9622 insertions(+), 9787 deletions(-) delete mode 100644 tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp create mode 100644 tests/benchmarks/corelib/io/qdir/10000/tst_bench_qdir_10000.cpp delete mode 100644 tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.cpp delete mode 100644 tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.qrc create mode 100644 tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.cpp create mode 100644 tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.qrc delete mode 100644 tests/benchmarks/corelib/io/qdiriterator/main.cpp create mode 100644 tests/benchmarks/corelib/io/qdiriterator/tst_bench_qdiriterator.cpp delete mode 100644 tests/benchmarks/corelib/io/qfileinfo/main.cpp create mode 100644 tests/benchmarks/corelib/io/qfileinfo/tst_bench_qfileinfo.cpp delete mode 100644 tests/benchmarks/corelib/io/qiodevice/main.cpp create mode 100644 tests/benchmarks/corelib/io/qiodevice/tst_bench_qiodevice.cpp create mode 100644 tests/benchmarks/corelib/io/qprocess/testProcessLoopback/loopback.cpp delete mode 100644 tests/benchmarks/corelib/io/qprocess/testProcessLoopback/main.cpp delete mode 100644 tests/benchmarks/corelib/io/qtemporaryfile/main.cpp create mode 100644 tests/benchmarks/corelib/io/qtemporaryfile/tst_bench_qtemporaryfile.cpp delete mode 100644 tests/benchmarks/corelib/io/qtextstream/main.cpp create mode 100644 tests/benchmarks/corelib/io/qtextstream/tst_bench_qtextstream.cpp delete mode 100644 tests/benchmarks/corelib/io/qurl/main.cpp create mode 100644 tests/benchmarks/corelib/io/qurl/tst_bench_qurl.cpp create mode 100644 tests/benchmarks/corelib/itemmodels/qsortfilterproxymodel/tst_bench_qsortfilterproxymodel.cpp delete mode 100644 tests/benchmarks/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp 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 delete mode 100644 tests/benchmarks/corelib/mimetypes/qmimedatabase/main.cpp create mode 100644 tests/benchmarks/corelib/mimetypes/qmimedatabase/tst_bench_qmimedatabase.cpp create mode 100644 tests/benchmarks/corelib/plugin/quuid/tst_bench_quuid.cpp delete mode 100644 tests/benchmarks/corelib/plugin/quuid/tst_quuid.cpp delete mode 100644 tests/benchmarks/corelib/text/qbytearray/main.cpp create mode 100644 tests/benchmarks/corelib/text/qbytearray/tst_bench_qbytearray.cpp delete mode 100644 tests/benchmarks/corelib/text/qchar/main.cpp create mode 100644 tests/benchmarks/corelib/text/qchar/tst_bench_qchar.cpp delete mode 100644 tests/benchmarks/corelib/text/qlocale/main.cpp create mode 100644 tests/benchmarks/corelib/text/qlocale/tst_bench_qlocale.cpp delete mode 100644 tests/benchmarks/corelib/text/qstringbuilder/main.cpp create mode 100644 tests/benchmarks/corelib/text/qstringbuilder/tst_bench_qstringbuilder.cpp delete mode 100644 tests/benchmarks/corelib/text/qstringlist/main.cpp create mode 100644 tests/benchmarks/corelib/text/qstringlist/tst_bench_qstringlist.cpp delete mode 100644 tests/benchmarks/corelib/text/qstringtokenizer/main.cpp create mode 100644 tests/benchmarks/corelib/text/qstringtokenizer/tst_bench_qstringtokenizer.cpp create mode 100644 tests/benchmarks/corelib/thread/qfuture/tst_bench_qfuture.cpp delete mode 100644 tests/benchmarks/corelib/thread/qfuture/tst_qfuture.cpp create mode 100644 tests/benchmarks/corelib/thread/qmutex/tst_bench_qmutex.cpp delete mode 100644 tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp create mode 100644 tests/benchmarks/corelib/thread/qreadwritelock/tst_bench_qreadwritelock.cpp delete mode 100644 tests/benchmarks/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp create mode 100644 tests/benchmarks/corelib/thread/qthreadpool/tst_bench_qthreadpool.cpp delete mode 100644 tests/benchmarks/corelib/thread/qthreadpool/tst_qthreadpool.cpp create mode 100644 tests/benchmarks/corelib/thread/qthreadstorage/tst_bench_qthreadstorage.cpp delete mode 100644 tests/benchmarks/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp create mode 100644 tests/benchmarks/corelib/thread/qwaitcondition/tst_bench_qwaitcondition.cpp delete mode 100644 tests/benchmarks/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp delete mode 100644 tests/benchmarks/corelib/time/qdatetime/main.cpp create mode 100644 tests/benchmarks/corelib/time/qdatetime/tst_bench_qdatetime.cpp delete mode 100644 tests/benchmarks/corelib/time/qtimezone/main.cpp create mode 100644 tests/benchmarks/corelib/time/qtimezone/tst_bench_qtimezone.cpp delete mode 100644 tests/benchmarks/corelib/tools/containers-associative/main.cpp create mode 100644 tests/benchmarks/corelib/tools/containers-associative/tst_bench_containers_associative.cpp delete mode 100644 tests/benchmarks/corelib/tools/containers-sequential/main.cpp create mode 100644 tests/benchmarks/corelib/tools/containers-sequential/tst_bench_containers_sequential.cpp delete mode 100644 tests/benchmarks/corelib/tools/qcontiguouscache/main.cpp create mode 100644 tests/benchmarks/corelib/tools/qcontiguouscache/tst_bench_qcontiguouscache.cpp delete mode 100644 tests/benchmarks/corelib/tools/qcryptographichash/main.cpp create mode 100644 tests/benchmarks/corelib/tools/qcryptographichash/tst_bench_qcryptographichash.cpp delete mode 100644 tests/benchmarks/corelib/tools/qhash/main.cpp delete mode 100644 tests/benchmarks/corelib/tools/qhash/main.h create mode 100644 tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.cpp create mode 100644 tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.h delete mode 100644 tests/benchmarks/corelib/tools/qlist/main.cpp create mode 100644 tests/benchmarks/corelib/tools/qlist/tst_bench_qlist.cpp delete mode 100644 tests/benchmarks/corelib/tools/qrect/main.cpp create mode 100644 tests/benchmarks/corelib/tools/qrect/tst_bench_qrect.cpp delete mode 100644 tests/benchmarks/corelib/tools/qringbuffer/main.cpp create mode 100644 tests/benchmarks/corelib/tools/qringbuffer/tst_bench_qringbuffer.cpp delete mode 100644 tests/benchmarks/corelib/tools/qset/main.cpp create mode 100644 tests/benchmarks/corelib/tools/qset/tst_bench_qset.cpp delete mode 100644 tests/benchmarks/corelib/tools/qstack/main.cpp create mode 100644 tests/benchmarks/corelib/tools/qstack/tst_bench_qstack.cpp (limited to 'tests') diff --git a/tests/benchmarks/corelib/io/CMakeLists.txt b/tests/benchmarks/corelib/io/CMakeLists.txt index 3419c4a28c..8d4b556abc 100644 --- a/tests/benchmarks/corelib/io/CMakeLists.txt +++ b/tests/benchmarks/corelib/io/CMakeLists.txt @@ -1,12 +1,11 @@ -# Generated from io.pro. - add_subdirectory(qdir) add_subdirectory(qdiriterator) add_subdirectory(qfile) add_subdirectory(qfileinfo) add_subdirectory(qiodevice) -add_subdirectory(qtemporaryfile) -add_subdirectory(qtextstream) if(QT_FEATURE_process) add_subdirectory(qprocess) endif() +add_subdirectory(qtemporaryfile) +add_subdirectory(qtextstream) +add_subdirectory(qurl) diff --git a/tests/benchmarks/corelib/io/qdir/10000/CMakeLists.txt b/tests/benchmarks/corelib/io/qdir/10000/CMakeLists.txt index e83c4e9acc..d1feaa5f18 100644 --- a/tests/benchmarks/corelib/io/qdir/10000/CMakeLists.txt +++ b/tests/benchmarks/corelib/io/qdir/10000/CMakeLists.txt @@ -1,15 +1,10 @@ -# Generated from 10000.pro. - ##################################################################### ## tst_bench_qdir_10000 Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qdir_10000 SOURCES - bench_qdir_10000.cpp + tst_bench_qdir_10000.cpp PUBLIC_LIBRARIES Qt::Test ) - -#### Keys ignored in scope 1:.:.:10000.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp b/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp deleted file mode 100644 index e02cfb3099..0000000000 --- a/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp +++ /dev/null @@ -1,198 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite module 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 - -#ifdef Q_OS_WIN -# include -#else -# include -# include -# include -# include -#endif - -class bench_QDir_10000 : public QObject{ - Q_OBJECT -public slots: - void initTestCase() { - QDir testdir = QDir::tempPath(); - - const QString subfolder_name = QLatin1String("test_speed"); - QVERIFY(testdir.mkdir(subfolder_name)); - QVERIFY(testdir.cd(subfolder_name)); - - for (uint i=0; i<10000; ++i) { - QFile file(testdir.absolutePath() + "/testfile_" + QString::number(i)); - file.open(QIODevice::WriteOnly); - } - } - void cleanupTestCase() { - { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - testdir.setSorting(QDir::Unsorted); - testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden); - foreach (const QString &filename, testdir.entryList()) { - testdir.remove(filename); - } - } - const QDir temp = QDir(QDir::tempPath()); - temp.rmdir(QLatin1String("test_speed")); - } -private slots: - void baseline() {} - - void sizeSpeed() { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - QBENCHMARK { - QFileInfoList fileInfoList = testdir.entryInfoList(QDir::Files, QDir::Unsorted); - foreach (const QFileInfo &fileInfo, fileInfoList) { - fileInfo.isDir(); - fileInfo.size(); - } - } - } - void sizeSpeedIterator() { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - QBENCHMARK { - QDirIterator dit(testdir.path(), QDir::Files); - while (dit.hasNext()) { - const auto fi = dit.nextFileInfo(); - (void)fi.isDir(); - (void)fi.size(); - } - } - } - - void sizeSpeedWithoutFilter() { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - QBENCHMARK { - QFileInfoList fileInfoList = testdir.entryInfoList(QDir::NoFilter, QDir::Unsorted); - foreach (const QFileInfo &fileInfo, fileInfoList) { - fileInfo.size(); - } - } - } - void sizeSpeedWithoutFilterIterator() { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - QBENCHMARK { - QDirIterator dit(testdir.path()); - while (dit.hasNext()) { - const auto fi = dit.nextFileInfo(); - (void)fi.isDir(); - (void)fi.size(); - } - } - } - - void sizeSpeedWithoutFileInfoList() { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - testdir.setSorting(QDir::Unsorted); - QBENCHMARK { - QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted); - foreach (const QString &filename, fileList) { - QFileInfo fileInfo(filename); - fileInfo.size(); - } - } - } - - void iDontWantAnyStat() { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - testdir.setSorting(QDir::Unsorted); - testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden); - QBENCHMARK { - QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted); - foreach (const QString &filename, fileList) { - Q_UNUSED(filename); - } - } - } - void iDontWantAnyStatIterator() { - QBENCHMARK { - QDirIterator dit(QDir::tempPath() + QLatin1String("/test_speed")); - while (dit.hasNext()) { - dit.next(); - } - } - } - - void sorted_byTime() { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); - testdir.setSorting(QDir::Time); - testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden); - QBENCHMARK { - QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Time); - foreach (const QString &filename, fileList) { - Q_UNUSED(filename); - } - } - } - - void sizeSpeedWithoutFilterLowLevel() { - QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); -#ifdef Q_OS_WIN - const wchar_t *dirpath = (wchar_t*)testdir.absolutePath().utf16(); - wchar_t appendedPath[MAX_PATH]; - wcscpy(appendedPath, dirpath); - wcscat(appendedPath, L"\\*"); - - WIN32_FIND_DATA fd; - HANDLE hSearch = FindFirstFileW(appendedPath, &fd); - QVERIFY(hSearch != INVALID_HANDLE_VALUE); - - QBENCHMARK { - do { - - } while (FindNextFile(hSearch, &fd)); - } - FindClose(hSearch); -#else - DIR *dir = opendir(qPrintable(testdir.absolutePath())); - QVERIFY(dir); - - QVERIFY(!chdir(qPrintable(testdir.absolutePath()))); - QBENCHMARK { - struct dirent *item = readdir(dir); - while (item) { - char *fileName = item->d_name; - - struct stat fileStat; - QVERIFY(!stat(fileName, &fileStat)); - - item = readdir(dir); - } - } - closedir(dir); -#endif - } -}; - -QTEST_MAIN(bench_QDir_10000) -#include "bench_qdir_10000.moc" diff --git a/tests/benchmarks/corelib/io/qdir/10000/tst_bench_qdir_10000.cpp b/tests/benchmarks/corelib/io/qdir/10000/tst_bench_qdir_10000.cpp new file mode 100644 index 0000000000..4ed1246a6c --- /dev/null +++ b/tests/benchmarks/corelib/io/qdir/10000/tst_bench_qdir_10000.cpp @@ -0,0 +1,211 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite module 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 + +#ifdef Q_OS_WIN +# include +#else +# include +# include +# include +# include +#endif + +class tst_QDir_10000 : public QObject +{ + Q_OBJECT +public slots: + void initTestCase() + { + QDir testdir = QDir::tempPath(); + + const QString subfolder_name = QLatin1String("test_speed"); + QVERIFY(testdir.mkdir(subfolder_name)); + QVERIFY(testdir.cd(subfolder_name)); + + for (uint i=0; i<10000; ++i) { + QFile file(testdir.absolutePath() + "/testfile_" + QString::number(i)); + file.open(QIODevice::WriteOnly); + } + } + void cleanupTestCase() + { + { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + testdir.setSorting(QDir::Unsorted); + testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden); + foreach (const QString &filename, testdir.entryList()) { + testdir.remove(filename); + } + } + const QDir temp = QDir(QDir::tempPath()); + temp.rmdir(QLatin1String("test_speed")); + } +private slots: + void baseline() {} + + void sizeSpeed() + { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + QBENCHMARK { + QFileInfoList fileInfoList = testdir.entryInfoList(QDir::Files, QDir::Unsorted); + foreach (const QFileInfo &fileInfo, fileInfoList) { + fileInfo.isDir(); + fileInfo.size(); + } + } + } + void sizeSpeedIterator() + { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + QBENCHMARK { + QDirIterator dit(testdir.path(), QDir::Files); + while (dit.hasNext()) { + const auto fi = dit.nextFileInfo(); + (void)fi.isDir(); + (void)fi.size(); + } + } + } + + void sizeSpeedWithoutFilter() + { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + QBENCHMARK { + QFileInfoList fileInfoList = testdir.entryInfoList(QDir::NoFilter, QDir::Unsorted); + foreach (const QFileInfo &fileInfo, fileInfoList) { + fileInfo.size(); + } + } + } + void sizeSpeedWithoutFilterIterator() + { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + QBENCHMARK { + QDirIterator dit(testdir.path()); + while (dit.hasNext()) { + const auto fi = dit.nextFileInfo(); + (void)fi.isDir(); + (void)fi.size(); + } + } + } + + void sizeSpeedWithoutFileInfoList() + { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + testdir.setSorting(QDir::Unsorted); + QBENCHMARK { + QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted); + foreach (const QString &filename, fileList) { + QFileInfo fileInfo(filename); + fileInfo.size(); + } + } + } + + void iDontWantAnyStat() + { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + testdir.setSorting(QDir::Unsorted); + testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden); + QBENCHMARK { + QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted); + foreach (const QString &filename, fileList) { + Q_UNUSED(filename); + } + } + } + void iDontWantAnyStatIterator() + { + QBENCHMARK { + QDirIterator dit(QDir::tempPath() + QLatin1String("/test_speed")); + while (dit.hasNext()) { + dit.next(); + } + } + } + + void sorted_byTime() + { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + testdir.setSorting(QDir::Time); + testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden); + QBENCHMARK { + QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Time); + foreach (const QString &filename, fileList) { + Q_UNUSED(filename); + } + } + } + + void sizeSpeedWithoutFilterLowLevel() + { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); +#ifdef Q_OS_WIN + const wchar_t *dirpath = (wchar_t*)testdir.absolutePath().utf16(); + wchar_t appendedPath[MAX_PATH]; + wcscpy(appendedPath, dirpath); + wcscat(appendedPath, L"\\*"); + + WIN32_FIND_DATA fd; + HANDLE hSearch = FindFirstFileW(appendedPath, &fd); + QVERIFY(hSearch != INVALID_HANDLE_VALUE); + + QBENCHMARK { + do { + + } while (FindNextFile(hSearch, &fd)); + } + FindClose(hSearch); +#else + DIR *dir = opendir(qPrintable(testdir.absolutePath())); + QVERIFY(dir); + + QVERIFY(!chdir(qPrintable(testdir.absolutePath()))); + QBENCHMARK { + struct dirent *item = readdir(dir); + while (item) { + char *fileName = item->d_name; + + struct stat fileStat; + QVERIFY(!stat(fileName, &fileStat)); + + item = readdir(dir); + } + } + closedir(dir); +#endif + } +}; + +QTEST_MAIN(tst_QDir_10000) + +#include "tst_bench_qdir_10000.moc" diff --git a/tests/benchmarks/corelib/io/qdir/CMakeLists.txt b/tests/benchmarks/corelib/io/qdir/CMakeLists.txt index 10185014fa..f1800fc0cd 100644 --- a/tests/benchmarks/corelib/io/qdir/CMakeLists.txt +++ b/tests/benchmarks/corelib/io/qdir/CMakeLists.txt @@ -1,3 +1,2 @@ -# Generated from qdir.pro. - add_subdirectory(10000) +add_subdirectory(tree) diff --git a/tests/benchmarks/corelib/io/qdir/tree/CMakeLists.txt b/tests/benchmarks/corelib/io/qdir/tree/CMakeLists.txt index c60bfcfdc3..32dea04edc 100644 --- a/tests/benchmarks/corelib/io/qdir/tree/CMakeLists.txt +++ b/tests/benchmarks/corelib/io/qdir/tree/CMakeLists.txt @@ -1,28 +1,22 @@ -# Generated from tree.pro. - ##################################################################### -## bench_qdir_tree Binary: +## tst_bench_qdir_tree Binary: ##################################################################### -qt_internal_add_benchmark(bench_qdir_tree +qt_internal_add_benchmark(tst_bench_qdir_tree SOURCES - bench_qdir_tree.cpp + tst_bench_qdir_tree.cpp PUBLIC_LIBRARIES Qt::Test ) # Resources: -set(bench_qdir_tree_resource_files +set(qdir_tree_resource_files "4.6.0-list.txt" ) -qt_internal_add_resource(bench_qdir_tree "bench_qdir_tree" +qt_internal_add_resource(tst_bench_qdir_tree "tst_bench_qdir_tree" PREFIX "/" FILES - ${bench_qdir_tree_resource_files} + ${qdir_tree_resource_files} ) - - -#### Keys ignored in scope 1:.:.:tree.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.cpp b/tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.cpp deleted file mode 100644 index df16a7978a..0000000000 --- a/tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.cpp +++ /dev/null @@ -1,225 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite module 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 "../../../../../shared/filesystem.h" - -class bench_QDir_tree - : public QObject -{ - Q_OBJECT - -public: - bench_QDir_tree() - : prefix("test-tree/"), - musicprefix(QLatin1String("music")), - photoprefix(QLatin1String("photos")), - sourceprefix(QLatin1String("source")), - musicsize(0), - photosize(0), - sourcesize(0) - { - } - -private: - QByteArray prefix; - QString musicprefix; - QString photoprefix; - QString sourceprefix; - qint64 musicsize; - qint64 photosize; - qint64 sourcesize; - FileSystem fs; // Uses QTemporaryDir to tidy away file tree created. - -private slots: - void initTestCase() - { - QFile list(":/4.6.0-list.txt"); - QVERIFY(list.open(QIODevice::ReadOnly | QIODevice::Text)); - - QVERIFY(fs.createDirectory(prefix)); - - QStack stack; - QByteArray line; - while (true) { - char ch; - if (!list.getChar(&ch)) - break; - if (ch != ' ') { - line.append(ch); - continue; - } - - int pop = 1; - if (!line.isEmpty()) - pop = line.toInt(); - - while (pop) { - stack.pop(); - --pop; - } - - line = list.readLine().trimmed(); - stack.push(line); - - line = prefix; - for (const QByteArray &pathElement : qAsConst(stack)) - line += pathElement; - - if (line.endsWith('/')) - QVERIFY(fs.createDirectory(line)); - else - QVERIFY(fs.createFile(line)); - - line.clear(); - } - - //Use case: music collection - 10 files in 100 directories (albums) - QVERIFY(fs.createDirectory(musicprefix)); - for (int i=0;i<1000;i++) { - if ((i % 10) == 0) - QVERIFY(fs.createDirectory(QString("%1/directory%2").arg(musicprefix).arg(i/10))); - qint64 size = fs.createFileWithContent(QString("%1/directory%2/file%3").arg(musicprefix).arg(i/10).arg(i)); - QVERIFY(size > 0); - musicsize += size; - } - //Use case: photos - 1000 files in 1 directory - QVERIFY(fs.createDirectory(photoprefix)); - for (int i=0;i<1000;i++) { - qint64 size = fs.createFileWithContent(QString("%1/file%2").arg(photoprefix).arg(i)); - QVERIFY(size > 0); - photosize += size; - } - //Use case: source - 10 files in 10 subdirectories in 10 directories (1000 total) - QVERIFY(fs.createDirectory(sourceprefix)); - for (int i=0;i<1000;i++) { - if ((i % 100) == 0) - QVERIFY(fs.createDirectory(QString("%1/directory%2").arg(sourceprefix).arg(i/100))); - if ((i % 10) == 0) - QVERIFY(fs.createDirectory(QString("%1/directory%2/subdirectory%3").arg(sourceprefix).arg(i/100).arg(i/10))); - qint64 size = fs.createFileWithContent(QString("%1/directory%2/subdirectory%3/file%4").arg(sourceprefix).arg(i/100).arg(i/10).arg(i)); - QVERIFY(size > 0); - sourcesize += size; - } - } - - void fileSearch_data() const - { - QTest::addColumn("nameFilters"); - QTest::addColumn("filter"); - QTest::addColumn("entryCount"); - - QTest::newRow("*.cpp") << QStringList("*.cpp") << int(QDir::Files) << 3791; - QTest::newRow("executables") - << QStringList("*") - << int(QDir::Executable | QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot) - << 536; - } - - void fileSearch() const - { - QFETCH(QStringList, nameFilters); - QFETCH(int, filter); - QFETCH(int, entryCount); - - int count = 0; - QBENCHMARK { - // Recursive directory iteration - QDirIterator iterator(fs.absoluteFilePath(prefix), - nameFilters, QDir::Filter(filter), - QDirIterator::Subdirectories | QDirIterator::FollowSymlinks); - - count = 0; - while (iterator.hasNext()) { - iterator.next(); - ++count; - } - - QCOMPARE(count, entryCount); - } - - QCOMPARE(count, entryCount); - } - - void traverseDirectory() const - { - int count = 0; - QBENCHMARK { - QDirIterator iterator( - fs.absoluteFilePath(prefix), - QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System, - QDirIterator::Subdirectories | QDirIterator::FollowSymlinks); - - count = 0; - while (iterator.hasNext()) { - iterator.next(); - ++count; - } - - QCOMPARE(count, 11906); - } - - QCOMPARE(count, 11906); - } - - void thousandFiles_data() const - { - QTest::addColumn("dirName"); - QTest::addColumn("expectedSize"); - QTest::newRow("music") << musicprefix << musicsize; - QTest::newRow("photos") << photoprefix << photosize; - QTest::newRow("src") << sourceprefix << sourcesize; - } - - void thousandFiles() const - { - QFETCH(QString, dirName); - QFETCH(qint64, expectedSize); - QBENCHMARK { - qint64 totalsize = 0; - int count = 0; - QDirIterator iter(fs.absoluteFilePath(dirName), - QDir::Files, QDirIterator::Subdirectories); - while(iter.hasNext()) { - count++; - totalsize += iter.nextFileInfo().size(); - } - QCOMPARE(count, 1000); - QCOMPARE(totalsize, expectedSize); - } - } -}; - -QTEST_MAIN(bench_QDir_tree) -#include "bench_qdir_tree.moc" diff --git a/tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.qrc b/tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.qrc deleted file mode 100644 index d57cb6c368..0000000000 --- a/tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.qrc +++ /dev/null @@ -1,5 +0,0 @@ - - - 4.6.0-list.txt - - diff --git a/tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.cpp b/tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.cpp new file mode 100644 index 0000000000..d960cb41e2 --- /dev/null +++ b/tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.cpp @@ -0,0 +1,226 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite module 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 "../../../../../shared/filesystem.h" + +class tst_QDir_tree + : public QObject +{ + Q_OBJECT + +public: + tst_QDir_tree() + : prefix("test-tree/"), + musicprefix(QLatin1String("music")), + photoprefix(QLatin1String("photos")), + sourceprefix(QLatin1String("source")), + musicsize(0), + photosize(0), + sourcesize(0) + { + } + +private: + QByteArray prefix; + QString musicprefix; + QString photoprefix; + QString sourceprefix; + qint64 musicsize; + qint64 photosize; + qint64 sourcesize; + FileSystem fs; // Uses QTemporaryDir to tidy away file tree created. + +private slots: + void initTestCase() + { + QFile list(":/4.6.0-list.txt"); + QVERIFY(list.open(QIODevice::ReadOnly | QIODevice::Text)); + + QVERIFY(fs.createDirectory(prefix)); + + QStack stack; + QByteArray line; + while (true) { + char ch; + if (!list.getChar(&ch)) + break; + if (ch != ' ') { + line.append(ch); + continue; + } + + int pop = 1; + if (!line.isEmpty()) + pop = line.toInt(); + + while (pop) { + stack.pop(); + --pop; + } + + line = list.readLine().trimmed(); + stack.push(line); + + line = prefix; + for (const QByteArray &pathElement : qAsConst(stack)) + line += pathElement; + + if (line.endsWith('/')) + QVERIFY(fs.createDirectory(line)); + else + QVERIFY(fs.createFile(line)); + + line.clear(); + } + + //Use case: music collection - 10 files in 100 directories (albums) + QVERIFY(fs.createDirectory(musicprefix)); + for (int i=0;i<1000;i++) { + if ((i % 10) == 0) + QVERIFY(fs.createDirectory(QString("%1/directory%2").arg(musicprefix).arg(i/10))); + qint64 size = fs.createFileWithContent(QString("%1/directory%2/file%3").arg(musicprefix).arg(i/10).arg(i)); + QVERIFY(size > 0); + musicsize += size; + } + //Use case: photos - 1000 files in 1 directory + QVERIFY(fs.createDirectory(photoprefix)); + for (int i=0;i<1000;i++) { + qint64 size = fs.createFileWithContent(QString("%1/file%2").arg(photoprefix).arg(i)); + QVERIFY(size > 0); + photosize += size; + } + //Use case: source - 10 files in 10 subdirectories in 10 directories (1000 total) + QVERIFY(fs.createDirectory(sourceprefix)); + for (int i=0;i<1000;i++) { + if ((i % 100) == 0) + QVERIFY(fs.createDirectory(QString("%1/directory%2").arg(sourceprefix).arg(i/100))); + if ((i % 10) == 0) + QVERIFY(fs.createDirectory(QString("%1/directory%2/subdirectory%3").arg(sourceprefix).arg(i/100).arg(i/10))); + qint64 size = fs.createFileWithContent(QString("%1/directory%2/subdirectory%3/file%4").arg(sourceprefix).arg(i/100).arg(i/10).arg(i)); + QVERIFY(size > 0); + sourcesize += size; + } + } + + void fileSearch_data() const + { + QTest::addColumn("nameFilters"); + QTest::addColumn("filter"); + QTest::addColumn("entryCount"); + + QTest::newRow("*.cpp") << QStringList("*.cpp") << int(QDir::Files) << 3791; + QTest::newRow("executables") + << QStringList("*") + << int(QDir::Executable | QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot) + << 536; + } + + void fileSearch() const + { + QFETCH(QStringList, nameFilters); + QFETCH(int, filter); + QFETCH(int, entryCount); + + int count = 0; + QBENCHMARK { + // Recursive directory iteration + QDirIterator iterator(fs.absoluteFilePath(prefix), + nameFilters, QDir::Filter(filter), + QDirIterator::Subdirectories | QDirIterator::FollowSymlinks); + + count = 0; + while (iterator.hasNext()) { + iterator.next(); + ++count; + } + + QCOMPARE(count, entryCount); + } + + QCOMPARE(count, entryCount); + } + + void traverseDirectory() const + { + int count = 0; + QBENCHMARK { + QDirIterator iterator( + fs.absoluteFilePath(prefix), + QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System, + QDirIterator::Subdirectories | QDirIterator::FollowSymlinks); + + count = 0; + while (iterator.hasNext()) { + iterator.next(); + ++count; + } + + QCOMPARE(count, 11906); + } + + QCOMPARE(count, 11906); + } + + void thousandFiles_data() const + { + QTest::addColumn("dirName"); + QTest::addColumn("expectedSize"); + QTest::newRow("music") << musicprefix << musicsize; + QTest::newRow("photos") << photoprefix << photosize; + QTest::newRow("src") << sourceprefix << sourcesize; + } + + void thousandFiles() const + { + QFETCH(QString, dirName); + QFETCH(qint64, expectedSize); + QBENCHMARK { + qint64 totalsize = 0; + int count = 0; + QDirIterator iter(fs.absoluteFilePath(dirName), + QDir::Files, QDirIterator::Subdirectories); + while(iter.hasNext()) { + count++; + totalsize += iter.nextFileInfo().size(); + } + QCOMPARE(count, 1000); + QCOMPARE(totalsize, expectedSize); + } + } +}; + +QTEST_MAIN(tst_QDir_tree) + +#include "tst_bench_qdir_tree.moc" diff --git a/tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.qrc b/tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.qrc new file mode 100644 index 0000000000..d57cb6c368 --- /dev/null +++ b/tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.qrc @@ -0,0 +1,5 @@ + + + 4.6.0-list.txt + + diff --git a/tests/benchmarks/corelib/io/qdiriterator/CMakeLists.txt b/tests/benchmarks/corelib/io/qdiriterator/CMakeLists.txt index 8ba331a113..f250a9627a 100644 --- a/tests/benchmarks/corelib/io/qdiriterator/CMakeLists.txt +++ b/tests/benchmarks/corelib/io/qdiriterator/CMakeLists.txt @@ -1,12 +1,10 @@ -# Generated from qdiriterator.pro. - ##################################################################### ## tst_bench_qdiriterator Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qdiriterator SOURCES - main.cpp + tst_bench_qdiriterator.cpp qfilesystemiterator.cpp qfilesystemiterator.h PUBLIC_LIBRARIES Qt::Test diff --git a/tests/benchmarks/corelib/io/qdiriterator/main.cpp b/tests/benchmarks/corelib/io/qdiriterator/main.cpp deleted file mode 100644 index acf1ede368..0000000000 --- a/tests/benchmarks/corelib/io/qdiriterator/main.cpp +++ /dev/null @@ -1,262 +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 - -#ifdef Q_OS_WIN -# include -#else -# include -# include -# include -# include -# include -#endif - -#include - -#include "qfilesystemiterator.h" - -#if QT_CONFIG(cxx17_filesystem) -#include -#endif - -class tst_qdiriterator : public QObject -{ - Q_OBJECT - - void data(); -private slots: - void posix(); - void posix_data() { data(); } - void diriterator(); - void diriterator_data() { data(); } - void fsiterator(); - void fsiterator_data() { data(); } - void stdRecursiveDirectoryIterator(); - void stdRecursiveDirectoryIterator_data() { data(); } -}; - -void tst_qdiriterator::data() -{ - const char hereRelative[] = "tests/benchmarks/corelib/io/qdiriterator"; - QByteArray dir(QT_TESTCASE_SOURCEDIR); - // qDebug("Source dir: %s", dir.constData()); - dir.chop(sizeof(hereRelative)); // Counts the '\0', making up for the omitted leading '/' - // qDebug("Root dir: %s", dir.constData()); - - QTest::addColumn("dirpath"); - const QByteArray ba = dir + "/src/corelib"; - - if (!QFileInfo(QString::fromLocal8Bit(ba)).isDir()) - QSKIP("Missing Qt directory"); - - QTest::newRow("corelib") << ba; - QTest::newRow("corelib/io") << (ba + "/io"); -} - -#ifdef Q_OS_WIN -static int posix_helper(const wchar_t *dirpath, size_t length) -{ - int count = 0; - HANDLE hSearch; - WIN32_FIND_DATA fd; - - wchar_t appendedPath[MAX_PATH]; - Q_ASSERT(MAX_PATH > length + 3); - wcsncpy(appendedPath, dirpath, length); - wcscpy(appendedPath + length, L"\\*"); - hSearch = FindFirstFile(appendedPath, &fd); - - if (hSearch == INVALID_HANDLE_VALUE) { - qWarning("FindFirstFile failed"); - return count; - } - - do { - if (!(fd.cFileName[0] == L'.' && fd.cFileName[1] == 0) && - !(fd.cFileName[0] == L'.' && fd.cFileName[1] == L'.' && fd.cFileName[2] == 0)) - { - if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - // newLength will "point" to where we put a * earlier, so we overwrite that. - size_t newLength = length + 1; // "+ 1" for directory separator - Q_ASSERT(newLength + wcslen(fd.cFileName) + 1 < MAX_PATH); // "+ 1" for null-terminator - wcscpy(appendedPath + newLength, fd.cFileName); - newLength += wcslen(fd.cFileName); - count += posix_helper(appendedPath, newLength); - } - else { - ++count; - } - } - } while (FindNextFile(hSearch, &fd)); - FindClose(hSearch); - - return count; -} - -#else - -static int posix_helper(const char *dirpath) -{ - //qDebug() << "DIR" << dirpath; - DIR *dir = ::opendir(dirpath); - if (!dir) - return 0; - - dirent *entry = 0; - - int count = 0; - while ((entry = ::readdir(dir))) { - if (qstrcmp(entry->d_name, ".") == 0) - continue; - if (qstrcmp(entry->d_name, "..") == 0) - continue; - ++count; - QByteArray ba = dirpath; - ba += '/'; - ba += entry->d_name; - QT_STATBUF st; - QT_LSTAT(ba.constData(), &st); - if (S_ISDIR(st.st_mode)) - count += posix_helper(ba.constData()); - } - - ::closedir(dir); - return count; -} -#endif - - -void tst_qdiriterator::posix() -{ - QFETCH(QByteArray, dirpath); - - int count = 0; - QString path(dirpath); - QBENCHMARK { -#ifdef Q_OS_WIN - wchar_t wPath[MAX_PATH]; - const int end = path.toWCharArray(wPath); - count = posix_helper(wPath, end); -#else - count = posix_helper(dirpath.constData()); -#endif - } - qDebug() << count; -} - -void tst_qdiriterator::diriterator() -{ - QFETCH(QByteArray, dirpath); - - int count = 0; - - QBENCHMARK { - int c = 0; - - QDirIterator dir(dirpath, - //QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot, - //QDir::AllEntries | QDir::Hidden, - QDir::Files, - QDirIterator::Subdirectories); - - while (dir.hasNext()) { - const auto fi = dir.nextFileInfo(); - //printf("%s\n", qPrintable(dir.fileName())); - 0 && printf("%d %s\n", - fi.isDir(), - //qPrintable(fi.absoluteFilePath()), - //qPrintable(dir.path()), - qPrintable(fi.filePath())); - ++c; - } - count = c; - } - qDebug() << count; -} - -void tst_qdiriterator::fsiterator() -{ - QFETCH(QByteArray, dirpath); - - int count = 0; - int dump = 0; - - QBENCHMARK { - int c = 0; - - dump && printf("\n\n\n\n"); - QDirIteratorTest::QFileSystemIterator dir(dirpath, - //QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot, - //QDir::AllEntries | QDir::Hidden, - //QDir::Files | QDir::NoDotAndDotDot, - QDir::Files, - QDirIteratorTest::QFileSystemIterator::Subdirectories); - - for (; !dir.atEnd(); dir.next()) { - dump && printf("%d %s\n", - dir.fileInfo().isDir(), - //qPrintable(dir.fileInfo().absoluteFilePath()), - //qPrintable(dir.path()), - qPrintable(dir.filePath()) - ); - ++c; - } - count = c; - } - qDebug() << count; -} - -void tst_qdiriterator::stdRecursiveDirectoryIterator() -{ -#if QT_CONFIG(cxx17_filesystem) - QFETCH(QByteArray, dirpath); - - int count = 0; - - QBENCHMARK { - int c = 0; - for (auto obj : std::filesystem::recursive_directory_iterator(dirpath.data())) { - if (obj.is_directory()) - continue; - c++; - } - count = c; - } - qDebug() << count; -#else - QSKIP("Not supported."); -#endif -} - -QTEST_MAIN(tst_qdiriterator) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/io/qdiriterator/tst_bench_qdiriterator.cpp b/tests/benchmarks/corelib/io/qdiriterator/tst_bench_qdiriterator.cpp new file mode 100644 index 0000000000..e22f235914 --- /dev/null +++ b/tests/benchmarks/corelib/io/qdiriterator/tst_bench_qdiriterator.cpp @@ -0,0 +1,262 @@ +/**************************************************************************** +** +** 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 + +#ifdef Q_OS_WIN +# include +#else +# include +# include +# include +# include +# include +#endif + +#include + +#include "qfilesystemiterator.h" + +#if QT_CONFIG(cxx17_filesystem) +#include +#endif + +class tst_QDirIterator : public QObject +{ + Q_OBJECT + + void data(); +private slots: + void posix(); + void posix_data() { data(); } + void diriterator(); + void diriterator_data() { data(); } + void fsiterator(); + void fsiterator_data() { data(); } + void stdRecursiveDirectoryIterator(); + void stdRecursiveDirectoryIterator_data() { data(); } +}; + +void tst_QDirIterator::data() +{ + const char hereRelative[] = "tests/benchmarks/corelib/io/qdiriterator"; + QByteArray dir(QT_TESTCASE_SOURCEDIR); + // qDebug("Source dir: %s", dir.constData()); + dir.chop(sizeof(hereRelative)); // Counts the '\0', making up for the omitted leading '/' + // qDebug("Root dir: %s", dir.constData()); + + QTest::addColumn("dirpath"); + const QByteArray ba = dir + "/src/corelib"; + + if (!QFileInfo(QString::fromLocal8Bit(ba)).isDir()) + QSKIP("Missing Qt directory"); + + QTest::newRow("corelib") << ba; + QTest::newRow("corelib/io") << (ba + "/io"); +} + +#ifdef Q_OS_WIN +static int posix_helper(const wchar_t *dirpath, size_t length) +{ + int count = 0; + HANDLE hSearch; + WIN32_FIND_DATA fd; + + wchar_t appendedPath[MAX_PATH]; + Q_ASSERT(MAX_PATH > length + 3); + wcsncpy(appendedPath, dirpath, length); + wcscpy(appendedPath + length, L"\\*"); + hSearch = FindFirstFile(appendedPath, &fd); + + if (hSearch == INVALID_HANDLE_VALUE) { + qWarning("FindFirstFile failed"); + return count; + } + + do { + if (!(fd.cFileName[0] == L'.' && fd.cFileName[1] == 0) && + !(fd.cFileName[0] == L'.' && fd.cFileName[1] == L'.' && fd.cFileName[2] == 0)) + { + if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { + // newLength will "point" to where we put a * earlier, so we overwrite that. + size_t newLength = length + 1; // "+ 1" for directory separator + Q_ASSERT(newLength + wcslen(fd.cFileName) + 1 < MAX_PATH); // "+ 1" for null-terminator + wcscpy(appendedPath + newLength, fd.cFileName); + newLength += wcslen(fd.cFileName); + count += posix_helper(appendedPath, newLength); + } + else { + ++count; + } + } + } while (FindNextFile(hSearch, &fd)); + FindClose(hSearch); + + return count; +} + +#else + +static int posix_helper(const char *dirpath) +{ + //qDebug() << "DIR" << dirpath; + DIR *dir = ::opendir(dirpath); + if (!dir) + return 0; + + dirent *entry = 0; + + int count = 0; + while ((entry = ::readdir(dir))) { + if (qstrcmp(entry->d_name, ".") == 0) + continue; + if (qstrcmp(entry->d_name, "..") == 0) + continue; + ++count; + QByteArray ba = dirpath; + ba += '/'; + ba += entry->d_name; + QT_STATBUF st; + QT_LSTAT(ba.constData(), &st); + if (S_ISDIR(st.st_mode)) + count += posix_helper(ba.constData()); + } + + ::closedir(dir); + return count; +} +#endif + + +void tst_QDirIterator::posix() +{ + QFETCH(QByteArray, dirpath); + + int count = 0; + QString path(dirpath); + QBENCHMARK { +#ifdef Q_OS_WIN + wchar_t wPath[MAX_PATH]; + const int end = path.toWCharArray(wPath); + count = posix_helper(wPath, end); +#else + count = posix_helper(dirpath.constData()); +#endif + } + qDebug() << count; +} + +void tst_QDirIterator::diriterator() +{ + QFETCH(QByteArray, dirpath); + + int count = 0; + + QBENCHMARK { + int c = 0; + + QDirIterator dir(dirpath, + //QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot, + //QDir::AllEntries | QDir::Hidden, + QDir::Files, + QDirIterator::Subdirectories); + + while (dir.hasNext()) { + const auto fi = dir.nextFileInfo(); + //printf("%s\n", qPrintable(dir.fileName())); + 0 && printf("%d %s\n", + fi.isDir(), + //qPrintable(fi.absoluteFilePath()), + //qPrintable(dir.path()), + qPrintable(fi.filePath())); + ++c; + } + count = c; + } + qDebug() << count; +} + +void tst_QDirIterator::fsiterator() +{ + QFETCH(QByteArray, dirpath); + + int count = 0; + int dump = 0; + + QBENCHMARK { + int c = 0; + + dump && printf("\n\n\n\n"); + QDirIteratorTest::QFileSystemIterator dir(dirpath, + //QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot, + //QDir::AllEntries | QDir::Hidden, + //QDir::Files | QDir::NoDotAndDotDot, + QDir::Files, + QDirIteratorTest::QFileSystemIterator::Subdirectories); + + for (; !dir.atEnd(); dir.next()) { + dump && printf("%d %s\n", + dir.fileInfo().isDir(), + //qPrintable(dir.fileInfo().absoluteFilePath()), + //qPrintable(dir.path()), + qPrintable(dir.filePath()) + ); + ++c; + } + count = c; + } + qDebug() << count; +} + +void tst_QDirIterator::stdRecursiveDirectoryIterator() +{ +#if QT_CONFIG(cxx17_filesystem) + QFETCH(QByteArray, dirpath); + + int count = 0; + + QBENCHMARK { + int c = 0; + for (auto obj : std::filesystem::recursive_directory_iterator(dirpath.data())) { + if (obj.is_directory()) + continue; + c++; + } + count = c; + } + qDebug() << count; +#else + QSKIP("Not supported."); +#endif +} + +QTEST_MAIN(tst_QDirIterator) + +#include "tst_bench_qdiriterator.moc" diff --git a/tests/benchmarks/corelib/io/qfileinfo/CMakeLists.txt b/tests/benchmarks/corelib/io/qfileinfo/CMakeLists.txt index 1c088bf71a..8933b30cf3 100644 --- a/tests/benchmarks/corelib/io/qfileinfo/CMakeLists.txt +++ b/tests/benchmarks/corelib/io/qfileinfo/CMakeLists.txt @@ -1,16 +1,11 @@ -# Generated from qfileinfo.pro. - ##################################################################### ## tst_bench_qfileinfo Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qfileinfo SOURCES - main.cpp + tst_bench_qfileinfo.cpp PUBLIC_LIBRARIES Qt::CorePrivate Qt::Test ) - -#### Keys ignored in scope 1:.:.:qfileinfo.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/io/qfileinfo/main.cpp b/tests/benchmarks/corelib/io/qfileinfo/main.cpp deleted file mode 100644 index 2cd06eef27..0000000000 --- a/tests/benchmarks/corelib/io/qfileinfo/main.cpp +++ /dev/null @@ -1,114 +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 -#include -#include - -#include "private/qfsfileengine_p.h" -#include "../../../../shared/filesystem.h" - -class qfileinfo : public QObject -{ - Q_OBJECT -private slots: - void existsTemporary(); - void existsStatic(); -#if defined(Q_OS_WIN) - void symLinkTargetPerformanceLNK(); - void junctionTargetPerformanceMountpoint(); -#endif - void initTestCase(); - void cleanupTestCase(); -public: - qfileinfo() : QObject() {}; -}; - -void qfileinfo::initTestCase() -{ -} - -void qfileinfo::cleanupTestCase() -{ -} - -void qfileinfo::existsTemporary() -{ - QString appPath = QCoreApplication::applicationFilePath(); - QBENCHMARK { QFileInfo(appPath).exists(); } -} - -void qfileinfo::existsStatic() -{ - QString appPath = QCoreApplication::applicationFilePath(); - QBENCHMARK { QFileInfo::exists(appPath); } -} - -#if defined(Q_OS_WIN) -void qfileinfo::symLinkTargetPerformanceLNK() -{ - QVERIFY(QFile::link("file","link.lnk")); - QFileInfo info("link.lnk"); - info.setCaching(false); - QVERIFY(info.isSymLink()); - QString linkTarget; - QBENCHMARK { - for(int i=0; i<100; i++) - linkTarget = info.symLinkTarget(); - } - QVERIFY(QFile::remove("link.lnk")); -} - -void qfileinfo::junctionTargetPerformanceMountpoint() -{ - wchar_t buffer[MAX_PATH]; - QString rootPath = QDir::toNativeSeparators(QDir::rootPath()); - QVERIFY(GetVolumeNameForVolumeMountPointW((LPCWSTR)rootPath.utf16(), buffer, MAX_PATH)); - QString rootVolume = QString::fromWCharArray(buffer); - QString mountpoint = "mountpoint"; - rootVolume.replace("\\\\?\\","\\??\\"); - const auto result = FileSystem::createNtfsJunction(rootVolume, mountpoint); - QVERIFY2(result.dwErr == ERROR_SUCCESS, qPrintable(result.errorMessage)); - - QFileInfo info(mountpoint); - info.setCaching(false); - QVERIFY(info.isJunction()); - QString junctionTarget; - QBENCHMARK { - for(int i=0; i<100; i++) - junctionTarget = info.junctionTarget(); - } - QVERIFY(QDir().rmdir(mountpoint)); -} -#endif - -QTEST_MAIN(qfileinfo) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/io/qfileinfo/tst_bench_qfileinfo.cpp b/tests/benchmarks/corelib/io/qfileinfo/tst_bench_qfileinfo.cpp new file mode 100644 index 0000000000..21dbf47ba2 --- /dev/null +++ b/tests/benchmarks/corelib/io/qfileinfo/tst_bench_qfileinfo.cpp @@ -0,0 +1,102 @@ +/**************************************************************************** +** +** 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 +#include +#include + +#include "private/qfsfileengine_p.h" +#include "../../../../shared/filesystem.h" + +class tst_QFileInfo : public QObject +{ + Q_OBJECT +private slots: + void existsTemporary(); + void existsStatic(); +#if defined(Q_OS_WIN) + void symLinkTargetPerformanceLNK(); + void junctionTargetPerformanceMountpoint(); +#endif +}; + +void tst_QFileInfo::existsTemporary() +{ + QString appPath = QCoreApplication::applicationFilePath(); + QBENCHMARK { QFileInfo(appPath).exists(); } +} + +void tst_QFileInfo::existsStatic() +{ + QString appPath = QCoreApplication::applicationFilePath(); + QBENCHMARK { QFileInfo::exists(appPath); } +} + +#if defined(Q_OS_WIN) +void tst_QFileInfo::symLinkTargetPerformanceLNK() +{ + QVERIFY(QFile::link("file","link.lnk")); + QFileInfo info("link.lnk"); + info.setCaching(false); + QVERIFY(info.isSymLink()); + QString linkTarget; + QBENCHMARK { + for(int i=0; i<100; i++) + linkTarget = info.symLinkTarget(); + } + QVERIFY(QFile::remove("link.lnk")); +} + +void tst_QFileInfo::junctionTargetPerformanceMountpoint() +{ + wchar_t buffer[MAX_PATH]; + QString rootPath = QDir::toNativeSeparators(QDir::rootPath()); + QVERIFY(GetVolumeNameForVolumeMountPointW((LPCWSTR)rootPath.utf16(), buffer, MAX_PATH)); + QString rootVolume = QString::fromWCharArray(buffer); + QString mountpoint = "mountpoint"; + rootVolume.replace("\\\\?\\","\\??\\"); + const auto result = FileSystem::createNtfsJunction(rootVolume, mountpoint); + QVERIFY2(result.dwErr == ERROR_SUCCESS, qPrintable(result.errorMessage)); + + QFileInfo info(mountpoint); + info.setCaching(false); + QVERIFY(info.isJunction()); + QString junctionTarget; + QBENCHMARK { + for(int i=0; i<100; i++) + junctionTarget = info.junctionTarget(); + } + QVERIFY(QDir().rmdir(mountpoint)); +} +#endif + +QTEST_MAIN(tst_QFileInfo) + +#include "tst_bench_qfileinfo.moc" diff --git a/tests/benchmarks/corelib/io/qiodevice/CMakeLists.txt b/tests/benchmarks/corelib/io/qiodevice/CMakeLists.txt index 3af6d4f214..ab8abc8788 100644 --- a/tests/benchmarks/corelib/io/qiodevice/CMakeLists.txt +++ b/tests/benchmarks/corelib/io/qiodevice/CMakeLists.txt @@ -1,15 +1,10 @@ -# Generated from qiodevice.pro. - ##################################################################### ## tst_bench_qiodevice Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qiodevice SOURCES - main.cpp + tst_bench_qiodevice.cpp PUBLIC_LIBRARIES Qt::Test ) - -#### Keys ignored in scope 1:.:.:qiodevice.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/io/qiodevice/main.cpp b/tests/benchmarks/corelib/io/qiodevice/main.cpp deleted file mode 100644 index de4660a253..0000000000 --- a/tests/benchmarks/corelib/io/qiodevice/main.cpp +++ /dev/null @@ -1,124 +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 - -#include - - -class tst_qiodevice : public QObject -{ - Q_OBJECT -private slots: - void read_old(); - void read_old_data() { read_data(); } - void peekAndRead(); - void peekAndRead_data() { read_data(); } - //void read_new(); - //void read_new_data() { read_data(); } -private: - void read_data(); -}; - - -void tst_qiodevice::read_data() -{ - QTest::addColumn("size"); - QTest::newRow("10k") << qint64(10 * 1024); - QTest::newRow("100k") << qint64(100 * 1024); - QTest::newRow("1000k") << qint64(1000 * 1024); - QTest::newRow("10000k") << qint64(10000 * 1024); - QTest::newRow("100000k") << qint64(100000 * 1024); - QTest::newRow("1000000k") << qint64(1000000 * 1024); -} - -void tst_qiodevice::read_old() -{ - QFETCH(qint64, size); - - QString name = "tmp" + QString::number(size); - - { - QFile file(name); - file.open(QIODevice::WriteOnly); - file.seek(size); - file.write("x", 1); - file.close(); - } - - QBENCHMARK { - QFile file(name); - file.open(QIODevice::ReadOnly); - QByteArray ba; - qint64 s = size - 1024; - file.seek(512); - ba = file.read(s); // crash happens during this read / assignment operation - } - - { - QFile file(name); - file.remove(); - } -} - -void tst_qiodevice::peekAndRead() -{ - QFETCH(qint64, size); - - QString name = "tmp" + QString::number(size); - - { - QFile file(name); - file.open(QIODevice::WriteOnly); - file.seek(size); - file.write("x", 1); - file.close(); - } - - QBENCHMARK { - QFile file(name); - file.open(QIODevice::ReadOnly); - - QByteArray ba(size / 1024, Qt::Uninitialized); - while (!file.atEnd()) { - file.peek(ba.data(), ba.size()); - file.read(ba.data(), ba.size()); - } - } - - { - QFile file(name); - file.remove(); - } -} - -QTEST_MAIN(tst_qiodevice) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/io/qiodevice/tst_bench_qiodevice.cpp b/tests/benchmarks/corelib/io/qiodevice/tst_bench_qiodevice.cpp new file mode 100644 index 0000000000..47e616b409 --- /dev/null +++ b/tests/benchmarks/corelib/io/qiodevice/tst_bench_qiodevice.cpp @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** 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 + +#include + +class tst_QIODevice : public QObject +{ + Q_OBJECT +private slots: + void read_old(); + void read_old_data() { read_data(); } + void peekAndRead(); + void peekAndRead_data() { read_data(); } + //void read_new(); + //void read_new_data() { read_data(); } +private: + void read_data(); +}; + + +void tst_QIODevice::read_data() +{ + QTest::addColumn("size"); + QTest::newRow("10k") << qint64(10 * 1024); + QTest::newRow("100k") << qint64(100 * 1024); + QTest::newRow("1000k") << qint64(1000 * 1024); + QTest::newRow("10000k") << qint64(10000 * 1024); + QTest::newRow("100000k") << qint64(100000 * 1024); + QTest::newRow("1000000k") << qint64(1000000 * 1024); +} + +void tst_QIODevice::read_old() +{ + QFETCH(qint64, size); + + QString name = "tmp" + QString::number(size); + + { + QFile file(name); + file.open(QIODevice::WriteOnly); + file.seek(size); + file.write("x", 1); + file.close(); + } + + QBENCHMARK { + QFile file(name); + file.open(QIODevice::ReadOnly); + QByteArray ba; + qint64 s = size - 1024; + file.seek(512); + ba = file.read(s); // crash happens during this read / assignment operation + } + + { + QFile file(name); + file.remove(); + } +} + +void tst_QIODevice::peekAndRead() +{ + QFETCH(qint64, size); + + QString name = "tmp" + QString::number(size); + + { + QFile file(name); + file.open(QIODevice::WriteOnly); + file.seek(size); + file.write("x", 1); + file.close(); + } + + QBENCHMARK { + QFile file(name); + file.open(QIODevice::ReadOnly); + + QByteArray ba(size / 1024, Qt::Uninitialized); + while (!file.atEnd()) { + file.peek(ba.data(), ba.size()); + file.read(ba.data(), ba.size()); + } + } + + { + QFile file(name); + file.remove(); + } +} + +QTEST_MAIN(tst_QIODevice) + +#include "tst_bench_qiodevice.moc" diff --git a/tests/benchmarks/corelib/io/qprocess/test/CMakeLists.txt b/tests/benchmarks/corelib/io/qprocess/test/CMakeLists.txt index ca7011a661..b08034e71d 100644 --- a/tests/benchmarks/corelib/io/qprocess/test/CMakeLists.txt +++ b/tests/benchmarks/corelib/io/qprocess/test/CMakeLists.txt @@ -1,5 +1,3 @@ -# Generated from test.pro. - ##################################################################### ## tst_bench_qprocess Binary: ##################################################################### diff --git a/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/CMakeLists.txt b/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/CMakeLists.txt index 896435b27b..a55a1e113a 100644 --- a/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/CMakeLists.txt +++ b/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/CMakeLists.txt @@ -2,4 +2,4 @@ ## testProcessLoopback Binary: ##################################################################### -add_executable(testProcessLoopback main.cpp) +add_executable(testProcessLoopback loopback.cpp) diff --git a/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/loopback.cpp b/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/loopback.cpp new file mode 100644 index 0000000000..1773ba7496 --- /dev/null +++ b/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/loopback.cpp @@ -0,0 +1,44 @@ +/**************************************************************************** +** +** 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 + +int main() +{ + char buffer[1024]; + for (;;) { + size_t num = fread(buffer, 1, sizeof(buffer), stdin); + if (num <= 0) + break; + fwrite(buffer, num, 1, stdout); + fflush(stdout); + } + + return 0; +} diff --git a/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/main.cpp b/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/main.cpp deleted file mode 100644 index 1773ba7496..0000000000 --- a/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/main.cpp +++ /dev/null @@ -1,44 +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 - -int main() -{ - char buffer[1024]; - for (;;) { - size_t num = fread(buffer, 1, sizeof(buffer), stdin); - if (num <= 0) - break; - fwrite(buffer, num, 1, stdout); - fflush(stdout); - } - - return 0; -} diff --git a/tests/benchmarks/corelib/io/qtemporaryfile/CMakeLists.txt b/tests/benchmarks/corelib/io/qtemporaryfile/CMakeLists.txt index a12bfd1260..5342cf8912 100644 --- a/tests/benchmarks/corelib/io/qtemporaryfile/CMakeLists.txt +++ b/tests/benchmarks/corelib/io/qtemporaryfile/CMakeLists.txt @@ -1,15 +1,10 @@ -# Generated from qtemporaryfile.pro. - ##################################################################### ## tst_bench_qtemporaryfile Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qtemporaryfile SOURCES - main.cpp + tst_bench_qtemporaryfile.cpp PUBLIC_LIBRARIES Qt::Test ) - -#### Keys ignored in scope 1:.:.:qtemporaryfile.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/io/qtemporaryfile/main.cpp b/tests/benchmarks/corelib/io/qtemporaryfile/main.cpp deleted file mode 100644 index c50032d174..0000000000 --- a/tests/benchmarks/corelib/io/qtemporaryfile/main.cpp +++ /dev/null @@ -1,90 +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 -#include -#include - - -class tst_qtemporaryfile : public QObject -{ - Q_OBJECT -private slots: - void openclose_data(); - void openclose(); - void readwrite_data() { openclose_data(); } - void readwrite(); - -private: -}; - -void tst_qtemporaryfile::openclose_data() -{ - QTest::addColumn("amount"); - QTest::newRow("100") << qint64(100); - QTest::newRow("1000") << qint64(1000); - QTest::newRow("10000") << qint64(10000); -} - -void tst_qtemporaryfile::openclose() -{ - QFETCH(qint64, amount); - - QBENCHMARK { - for (qint64 i = 0; i < amount; ++i) { - QTemporaryFile file; - file.open(); - file.close(); - } - } -} - -void tst_qtemporaryfile::readwrite() -{ - QFETCH(qint64, amount); - - const int dataSize = 4096; - QByteArray data; - data.fill('a', dataSize); - QBENCHMARK { - for (qint64 i = 0; i < amount; ++i) { - QTemporaryFile file; - file.open(); - file.write(data); - file.seek(0); - file.read(dataSize); - file.close(); - } - } -} - -QTEST_MAIN(tst_qtemporaryfile) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/io/qtemporaryfile/tst_bench_qtemporaryfile.cpp b/tests/benchmarks/corelib/io/qtemporaryfile/tst_bench_qtemporaryfile.cpp new file mode 100644 index 0000000000..fb855f1eda --- /dev/null +++ b/tests/benchmarks/corelib/io/qtemporaryfile/tst_bench_qtemporaryfile.cpp @@ -0,0 +1,89 @@ +/**************************************************************************** +** +** 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 +#include +#include + +class tst_QTemporaryFile : public QObject +{ + Q_OBJECT +private slots: + void openclose_data(); + void openclose(); + void readwrite_data() { openclose_data(); } + void readwrite(); + +private: +}; + +void tst_QTemporaryFile::openclose_data() +{ + QTest::addColumn("amount"); + QTest::newRow("100") << qint64(100); + QTest::newRow("1000") << qint64(1000); + QTest::newRow("10000") << qint64(10000); +} + +void tst_QTemporaryFile::openclose() +{ + QFETCH(qint64, amount); + + QBENCHMARK { + for (qint64 i = 0; i < amount; ++i) { + QTemporaryFile file; + file.open(); + file.close(); + } + } +} + +void tst_QTemporaryFile::readwrite() +{ + QFETCH(qint64, amount); + + const int dataSize = 4096; + QByteArray data; + data.fill('a', dataSize); + QBENCHMARK { + for (qint64 i = 0; i < amount; ++i) { + QTemporaryFile file; + file.open(); + file.write(data); + file.seek(0); + file.read(dataSize); + file.close(); + } + } +} + +QTEST_MAIN(tst_QTemporaryFile) + +#include "tst_bench_qtemporaryfile.moc" diff --git a/tests/benchmarks/corelib/io/qtextstream/CMakeLists.txt b/tests/benchmarks/corelib/io/qtextstream/CMakeLists.txt index 0393b91119..b54610ad74 100644 --- a/tests/benchmarks/corelib/io/qtextstream/CMakeLists.txt +++ b/tests/benchmarks/corelib/io/qtextstream/CMakeLists.txt @@ -1,15 +1,10 @@ -# Generated from qtextstream.pro. - ##################################################################### ## tst_bench_qtextstream Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qtextstream SOURCES - main.cpp + tst_bench_qtextstream.cpp PUBLIC_LIBRARIES Qt::Test ) - -#### Keys ignored in scope 1:.:.:qtextstream.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/io/qtextstream/main.cpp b/tests/benchmarks/corelib/io/qtextstream/main.cpp deleted file mode 100644 index 03dc3d1694..0000000000 --- a/tests/benchmarks/corelib/io/qtextstream/main.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2014 David Faure -** 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 - -class tst_qtextstream : public QObject -{ - Q_OBJECT -private slots: - void writeSingleChar_data(); - void writeSingleChar(); - -private: -}; - -enum Output { StringOutput, DeviceOutput }; -Q_DECLARE_METATYPE(Output); - -enum Input { CharStarInput, QStringInput, CharInput, QCharInput }; -Q_DECLARE_METATYPE(Input); - -void tst_qtextstream::writeSingleChar_data() -{ - QTest::addColumn("output"); - QTest::addColumn("input"); - - QTest::newRow("string_charstar") << StringOutput << CharStarInput; - QTest::newRow("string_string") << StringOutput << QStringInput; - QTest::newRow("string_char") << StringOutput << CharInput; - QTest::newRow("string_qchar") << StringOutput << QCharInput; - QTest::newRow("device_charstar") << DeviceOutput << CharStarInput; - QTest::newRow("device_string") << DeviceOutput << QStringInput; - QTest::newRow("device_char") << DeviceOutput << CharInput; - QTest::newRow("device_qchar") << DeviceOutput << QCharInput; -} - -void tst_qtextstream::writeSingleChar() -{ - QFETCH(Output, output); - QFETCH(Input, input); - - QString str; - QBuffer buffer; - QTextStream stream; - if (output == StringOutput) { - stream.setString(&str, QIODevice::WriteOnly); - } else { - QVERIFY(buffer.open(QIODevice::WriteOnly)); - stream.setDevice(&buffer); - } - // Test many different ways to write a single char into a QTextStream - QString inputString = "h"; - const int amount = 100000; - switch (input) { - case CharStarInput: - QBENCHMARK { - for (qint64 i = 0; i < amount; ++i) - stream << "h"; - } - break; - case QStringInput: - QBENCHMARK { - for (qint64 i = 0; i < amount; ++i) - stream << inputString; - } - break; - case CharInput: - QBENCHMARK { - for (qint64 i = 0; i < amount; ++i) - stream << 'h'; - } - break; - case QCharInput: - QBENCHMARK { - for (qint64 i = 0; i < amount; ++i) - stream << QChar('h'); - } - break; - } - QString result; - if (output == StringOutput) - result = str; - else - result = QString(buffer.data()); - - QCOMPARE(result.left(10), QString("hhhhhhhhhh")); -} - -QTEST_MAIN(tst_qtextstream) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/io/qtextstream/tst_bench_qtextstream.cpp b/tests/benchmarks/corelib/io/qtextstream/tst_bench_qtextstream.cpp new file mode 100644 index 0000000000..1da0d90c79 --- /dev/null +++ b/tests/benchmarks/corelib/io/qtextstream/tst_bench_qtextstream.cpp @@ -0,0 +1,120 @@ +/**************************************************************************** +** +** Copyright (C) 2014 David Faure +** 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 + +class tst_QTextStream : public QObject +{ + Q_OBJECT +private slots: + void writeSingleChar_data(); + void writeSingleChar(); + +private: +}; + +enum Output { StringOutput, DeviceOutput }; +Q_DECLARE_METATYPE(Output); + +enum Input { CharStarInput, QStringInput, CharInput, QCharInput }; +Q_DECLARE_METATYPE(Input); + +void tst_QTextStream::writeSingleChar_data() +{ + QTest::addColumn("output"); + QTest::addColumn("input"); + + QTest::newRow("string_charstar") << StringOutput << CharStarInput; + QTest::newRow("string_string") << StringOutput << QStringInput; + QTest::newRow("string_char") << StringOutput << CharInput; + QTest::newRow("string_qchar") << StringOutput << QCharInput; + QTest::newRow("device_charstar") << DeviceOutput << CharStarInput; + QTest::newRow("device_string") << DeviceOutput << QStringInput; + QTest::newRow("device_char") << DeviceOutput << CharInput; + QTest::newRow("device_qchar") << DeviceOutput << QCharInput; +} + +void tst_QTextStream::writeSingleChar() +{ + QFETCH(Output, output); + QFETCH(Input, input); + + QString str; + QBuffer buffer; + QTextStream stream; + if (output == StringOutput) { + stream.setString(&str, QIODevice::WriteOnly); + } else { + QVERIFY(buffer.open(QIODevice::WriteOnly)); + stream.setDevice(&buffer); + } + // Test many different ways to write a single char into a QTextStream + QString inputString = "h"; + const int amount = 100000; + switch (input) { + case CharStarInput: + QBENCHMARK { + for (qint64 i = 0; i < amount; ++i) + stream << "h"; + } + break; + case QStringInput: + QBENCHMARK { + for (qint64 i = 0; i < amount; ++i) + stream << inputString; + } + break; + case CharInput: + QBENCHMARK { + for (qint64 i = 0; i < amount; ++i) + stream << 'h'; + } + break; + case QCharInput: + QBENCHMARK { + for (qint64 i = 0; i < amount; ++i) + stream << QChar('h'); + } + break; + } + QString result; + if (output == StringOutput) + result = str; + else + result = QString(buffer.data()); + + QCOMPARE(result.left(10), QString("hhhhhhhhhh")); +} + +QTEST_MAIN(tst_QTextStream) + +#include "tst_bench_qtextstream.moc" diff --git a/tests/benchmarks/corelib/io/qurl/CMakeLists.txt b/tests/benchmarks/corelib/io/qurl/CMakeLists.txt index d38c8b18c0..e9c155ad3f 100644 --- a/tests/benchmarks/corelib/io/qurl/CMakeLists.txt +++ b/tests/benchmarks/corelib/io/qurl/CMakeLists.txt @@ -1,23 +1,18 @@ -# Generated from qurl.pro. - ##################################################################### ## tst_qurl Binary: ##################################################################### -qt_internal_add_benchmark(tst_qurl +qt_internal_add_benchmark(tst_bench_qurl SOURCES - main.cpp + tst_bench_qurl.cpp PUBLIC_LIBRARIES Qt::Test ) -#### Keys ignored in scope 1:.:.:qurl.pro:: -# TEMPLATE = "app" - ## Scopes: ##################################################################### -qt_internal_extend_target(tst_qurl CONDITION WIN32 +qt_internal_extend_target(tst_bench_qurl CONDITION WIN32 DEFINES _CRT_SECURE_NO_WARNINGS ) diff --git a/tests/benchmarks/corelib/io/qurl/main.cpp b/tests/benchmarks/corelib/io/qurl/main.cpp deleted file mode 100644 index 5ad3c3bd47..0000000000 --- a/tests/benchmarks/corelib/io/qurl/main.cpp +++ /dev/null @@ -1,208 +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_qurl: public QObject -{ - Q_OBJECT - -private slots: - void emptyUrl(); - void relativeUrl(); - void absoluteUrl(); - void isRelative_data(); - void isRelative(); - void toLocalFile_data(); - void toLocalFile(); - void toString_data(); - void toString(); - void resolved_data(); - void resolved(); - void equality_data(); - void equality(); - void qmlPropertyWriteUseCase(); - -private: - void generateFirstRunData(); -}; - -void tst_qurl::emptyUrl() -{ - QBENCHMARK { - QUrl url; - } -} - -void tst_qurl::relativeUrl() -{ - QBENCHMARK { - QUrl url("pics/avatar.png"); - } -} - -void tst_qurl::absoluteUrl() -{ - QBENCHMARK { - QUrl url("/tmp/avatar.png"); - } -} - -void tst_qurl::generateFirstRunData() -{ - QTest::addColumn("firstRun"); - - QTest::newRow("construction + first run") << true; - QTest::newRow("subsequent runs") << false; -} - -void tst_qurl::isRelative_data() -{ - generateFirstRunData(); -} - -void tst_qurl::isRelative() -{ - QFETCH(bool, firstRun); - if (firstRun) { - QBENCHMARK { - QUrl url("pics/avatar.png"); - url.isRelative(); - } - } else { - QUrl url("pics/avatar.png"); - QBENCHMARK { - url.isRelative(); - } - } -} - -void tst_qurl::toLocalFile_data() -{ - generateFirstRunData(); -} - -void tst_qurl::toLocalFile() -{ - QFETCH(bool, firstRun); - if (firstRun) { - QBENCHMARK { - QUrl url("/tmp/avatar.png"); - url.toLocalFile(); - } - } else { - QUrl url("/tmp/avatar.png"); - QBENCHMARK { - url.toLocalFile(); - } - } -} - -void tst_qurl::toString_data() -{ - generateFirstRunData(); -} - -void tst_qurl::toString() -{ - QFETCH(bool, firstRun); - if(firstRun) { - QBENCHMARK { - QUrl url("pics/avatar.png"); - url.toString(); - } - } else { - QUrl url("pics/avatar.png"); - QBENCHMARK { - url.toString(); - } - } -} - -void tst_qurl::resolved_data() -{ - generateFirstRunData(); -} - -void tst_qurl::resolved() -{ - QFETCH(bool, firstRun); - if(firstRun) { - QBENCHMARK { - QUrl baseUrl("/home/user/"); - QUrl url("pics/avatar.png"); - baseUrl.resolved(url); - } - } else { - QUrl baseUrl("/home/user/"); - QUrl url("pics/avatar.png"); - QBENCHMARK { - baseUrl.resolved(url); - } - } -} - -void tst_qurl::equality_data() -{ - generateFirstRunData(); -} - -void tst_qurl::equality() -{ - QFETCH(bool, firstRun); - if(firstRun) { - QBENCHMARK { - QUrl url("pics/avatar.png"); - QUrl url2("pics/avatar2.png"); - //url == url2; - } - } else { - QUrl url("pics/avatar.png"); - QUrl url2("pics/avatar2.png"); - QBENCHMARK { - url == url2; - } - } -} - -void tst_qurl::qmlPropertyWriteUseCase() -{ - QUrl base("file:///home/user/qt/examples/declarative/samegame/SamegameCore/"); - QString str("pics/redStar.png"); - - QBENCHMARK { - QUrl u = QUrl(str); - if (!u.isEmpty() && u.isRelative()) - u = base.resolved(u); - } -} - -QTEST_MAIN(tst_qurl) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/io/qurl/tst_bench_qurl.cpp b/tests/benchmarks/corelib/io/qurl/tst_bench_qurl.cpp new file mode 100644 index 0000000000..8165f8d059 --- /dev/null +++ b/tests/benchmarks/corelib/io/qurl/tst_bench_qurl.cpp @@ -0,0 +1,210 @@ +/**************************************************************************** +** +** 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_QUrl : public QObject +{ + Q_OBJECT + +private slots: + void emptyUrl(); + void relativeUrl(); + void absoluteUrl(); + void isRelative_data(); + void isRelative(); + void toLocalFile_data(); + void toLocalFile(); + void toString_data(); + void toString(); + void resolved_data(); + void resolved(); + void equality_data(); + void equality(); + void qmlPropertyWriteUseCase(); + +private: + void generateFirstRunData(); +}; + +void tst_QUrl::emptyUrl() +{ + QBENCHMARK { + QUrl url; + } +} + +void tst_QUrl::relativeUrl() +{ + QBENCHMARK { + QUrl url("pics/avatar.png"); + } +} + +void tst_QUrl::absoluteUrl() +{ + QBENCHMARK { + QUrl url("/tmp/avatar.png"); + } +} + +void tst_QUrl::generateFirstRunData() +{ + QTest::addColumn("firstRun"); + + QTest::newRow("construction + first run") << true; + QTest::newRow("subsequent runs") << false; +} + +void tst_QUrl::isRelative_data() +{ + generateFirstRunData(); +} + +void tst_QUrl::isRelative() +{ + QFETCH(bool, firstRun); + if (firstRun) { + QBENCHMARK { + QUrl url("pics/avatar.png"); + url.isRelative(); + } + } else { + QUrl url("pics/avatar.png"); + QBENCHMARK { + url.isRelative(); + } + } +} + +void tst_QUrl::toLocalFile_data() +{ + generateFirstRunData(); +} + +void tst_QUrl::toLocalFile() +{ + QFETCH(bool, firstRun); + if (firstRun) { + QBENCHMARK { + QUrl url("/tmp/avatar.png"); + url.toLocalFile(); + } + } else { + QUrl url("/tmp/avatar.png"); + QBENCHMARK { + url.toLocalFile(); + } + } +} + +void tst_QUrl::toString_data() +{ + generateFirstRunData(); +} + +void tst_QUrl::toString() +{ + QFETCH(bool, firstRun); + if(firstRun) { + QBENCHMARK { + QUrl url("pics/avatar.png"); + url.toString(); + } + } else { + QUrl url("pics/avatar.png"); + QBENCHMARK { + url.toString(); + } + } +} + +void tst_QUrl::resolved_data() +{ + generateFirstRunData(); +} + +void tst_QUrl::resolved() +{ + QFETCH(bool, firstRun); + QUrl expect("/home/user/pics/avatar.png"), actual; + if (firstRun) { + QBENCHMARK { + QUrl baseUrl("/home/user/"); + QUrl url("pics/avatar.png"); + actual = baseUrl.resolved(url); + } + } else { + QUrl baseUrl("/home/user/"); + QUrl url("pics/avatar.png"); + QBENCHMARK { + actual = baseUrl.resolved(url); + } + } + QCOMPARE(actual, expect); +} + +void tst_QUrl::equality_data() +{ + generateFirstRunData(); +} + +void tst_QUrl::equality() +{ + QFETCH(bool, firstRun); + if(firstRun) { + QBENCHMARK { + QUrl url("pics/avatar.png"); + QUrl url2("pics/avatar2.png"); + //url == url2; + } + } else { + QUrl url("pics/avatar.png"); + QUrl url2("pics/avatar2.png"); + QBENCHMARK { + url == url2; + } + } +} + +void tst_QUrl::qmlPropertyWriteUseCase() +{ + QUrl base("file:///home/user/qt/examples/declarative/samegame/SamegameCore/"); + QString str("pics/redStar.png"); + + QBENCHMARK { + QUrl u = QUrl(str); + if (!u.isEmpty() && u.isRelative()) + u = base.resolved(u); + } +} + +QTEST_MAIN(tst_QUrl) + +#include "tst_bench_qurl.moc" diff --git a/tests/benchmarks/corelib/itemmodels/qsortfilterproxymodel/CMakeLists.txt b/tests/benchmarks/corelib/itemmodels/qsortfilterproxymodel/CMakeLists.txt index a18678159b..4ae255bbb4 100644 --- a/tests/benchmarks/corelib/itemmodels/qsortfilterproxymodel/CMakeLists.txt +++ b/tests/benchmarks/corelib/itemmodels/qsortfilterproxymodel/CMakeLists.txt @@ -1,6 +1,6 @@ qt_internal_add_benchmark(tst_bench_qsortfilterproxymodel SOURCES - tst_qsortfilterproxymodel.cpp + tst_bench_qsortfilterproxymodel.cpp PUBLIC_LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/itemmodels/qsortfilterproxymodel/tst_bench_qsortfilterproxymodel.cpp b/tests/benchmarks/corelib/itemmodels/qsortfilterproxymodel/tst_bench_qsortfilterproxymodel.cpp new file mode 100644 index 0000000000..7c641a42ae --- /dev/null +++ b/tests/benchmarks/corelib/itemmodels/qsortfilterproxymodel/tst_bench_qsortfilterproxymodel.cpp @@ -0,0 +1,123 @@ +/**************************************************************************** +** +** Copyright (C) 2021 Igor Kushnir +** 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 + +static void resizeNumberList(QStringList &numberList, int size) +{ + if (!numberList.empty()) + QCOMPARE(numberList.constLast(), QString::number(numberList.size())); + + if (numberList.size() < size) { + numberList.reserve(size); + for (int i = numberList.size() + 1; i <= size; ++i) + numberList.push_back(QString::number(i)); + } else if (numberList.size() > size) { + numberList.erase(numberList.begin() + size, numberList.end()); + } + + QCOMPARE(numberList.size(), size); + if (!numberList.empty()) + QCOMPARE(numberList.constLast(), QString::number(numberList.size())); +} + +class tst_QSortFilterProxyModel : public QObject +{ + Q_OBJECT +private slots: + void clearFilter_data(); + void clearFilter(); + +private: + QStringList m_numberList; ///< Cache the strings for efficiency. +}; + +void tst_QSortFilterProxyModel::clearFilter_data() +{ + QTest::addColumn("itemCount"); + QTest::addColumn("pattern"); + QTest::addColumn("filteredRowCount"); + + const auto matchSingleItem = [](int item) { return QStringLiteral("^%1$").arg(item); }; + + for (int thousandItemCount : { 10, 25, 50, 100, 250, 500, 1000, 2000 }) { + const auto itemCount = thousandItemCount * 1000; + + QTest::addRow("no match in %dK", thousandItemCount) << itemCount << "-" << 0; + QTest::addRow("match all in %dK", thousandItemCount) << itemCount << "\\d+" << itemCount; + + QTest::addRow("match first in %dK", thousandItemCount) + << itemCount << matchSingleItem(1) << 1; + QTest::addRow("match 1000th in %dK", thousandItemCount) + << itemCount << matchSingleItem(1000) << 1; + QTest::addRow("match middle in %dK", thousandItemCount) + << itemCount << matchSingleItem(itemCount / 2) << 1; + QTest::addRow("match 1000th from end in %dK", thousandItemCount) + << itemCount << matchSingleItem(itemCount - 999) << 1; + QTest::addRow("match last in %dK", thousandItemCount) + << itemCount << matchSingleItem(itemCount) << 1; + + QTest::addRow("match each 10'000th in %dK", thousandItemCount) + << itemCount << "0000$" << thousandItemCount / 10; + QTest::addRow("match each 100'000th in %dK", thousandItemCount) + << itemCount << "00000$" << thousandItemCount / 100; + } +} + +void tst_QSortFilterProxyModel::clearFilter() +{ + QFETCH(const int, itemCount); + resizeNumberList(m_numberList, itemCount); + QStringListModel model(qAsConst(m_numberList)); + QCOMPARE(model.rowCount(), itemCount); + + QSortFilterProxyModel proxy; + proxy.setSourceModel(&model); + QCOMPARE(model.rowCount(), itemCount); + QCOMPARE(proxy.rowCount(), itemCount); + + QFETCH(const QString, pattern); + QFETCH(const int, filteredRowCount); + proxy.setFilterRegularExpression(pattern); + QCOMPARE(model.rowCount(), itemCount); + QCOMPARE(proxy.rowCount(), filteredRowCount); + + QBENCHMARK_ONCE { + proxy.setFilterRegularExpression(QString()); + } + QCOMPARE(model.rowCount(), itemCount); + QCOMPARE(proxy.rowCount(), itemCount); +} + +QTEST_MAIN(tst_QSortFilterProxyModel) + +#include "tst_bench_qsortfilterproxymodel.moc" diff --git a/tests/benchmarks/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp b/tests/benchmarks/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp deleted file mode 100644 index f7fc0963bc..0000000000 --- a/tests/benchmarks/corelib/itemmodels/qsortfilterproxymodel/tst_qsortfilterproxymodel.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2021 Igor Kushnir -** 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 - -static void resizeNumberList(QStringList &numberList, int size) -{ - if (!numberList.empty()) - QCOMPARE(numberList.constLast(), QString::number(numberList.size())); - - if (numberList.size() < size) { - numberList.reserve(size); - for (int i = numberList.size() + 1; i <= size; ++i) - numberList.push_back(QString::number(i)); - } else if (numberList.size() > size) { - numberList.erase(numberList.begin() + size, numberList.end()); - } - - QCOMPARE(numberList.size(), size); - if (!numberList.empty()) - QCOMPARE(numberList.constLast(), QString::number(numberList.size())); -} - -class tst_QSortFilterProxyModel : public QObject -{ - Q_OBJECT -private slots: - void clearFilter_data(); - void clearFilter(); - -private: - QStringList m_numberList; ///< Cache the strings for efficiency. -}; - -void tst_QSortFilterProxyModel::clearFilter_data() -{ - QTest::addColumn("itemCount"); - QTest::addColumn("pattern"); - QTest::addColumn("filteredRowCount"); - - const auto matchSingleItem = [](int item) { return QStringLiteral("^%1$").arg(item); }; - - for (int thousandItemCount : { 10, 25, 50, 100, 250, 500, 1000, 2000 }) { - const auto itemCount = thousandItemCount * 1000; - - QTest::addRow("no match in %dK", thousandItemCount) << itemCount << "-" << 0; - QTest::addRow("match all in %dK", thousandItemCount) << itemCount << "\\d+" << itemCount; - - QTest::addRow("match first in %dK", thousandItemCount) - << itemCount << matchSingleItem(1) << 1; - QTest::addRow("match 1000th in %dK", thousandItemCount) - << itemCount << matchSingleItem(1000) << 1; - QTest::addRow("match middle in %dK", thousandItemCount) - << itemCount << matchSingleItem(itemCount / 2) << 1; - QTest::addRow("match 1000th from end in %dK", thousandItemCount) - << itemCount << matchSingleItem(itemCount - 999) << 1; - QTest::addRow("match last in %dK", thousandItemCount) - << itemCount << matchSingleItem(itemCount) << 1; - - QTest::addRow("match each 10'000th in %dK", thousandItemCount) - << itemCount << "0000$" << thousandItemCount / 10; - QTest::addRow("match each 100'000th in %dK", thousandItemCount) - << itemCount << "00000$" << thousandItemCount / 100; - } -} - -void tst_QSortFilterProxyModel::clearFilter() -{ - QFETCH(const int, itemCount); - resizeNumberList(m_numberList, itemCount); - QStringListModel model(qAsConst(m_numberList)); - QCOMPARE(model.rowCount(), itemCount); - - QSortFilterProxyModel proxy; - proxy.setSourceModel(&model); - QCOMPARE(model.rowCount(), itemCount); - QCOMPARE(proxy.rowCount(), itemCount); - - QFETCH(const QString, pattern); - QFETCH(const int, filteredRowCount); - proxy.setFilterRegularExpression(pattern); - QCOMPARE(model.rowCount(), itemCount); - QCOMPARE(proxy.rowCount(), filteredRowCount); - - QBENCHMARK_ONCE { - proxy.setFilterRegularExpression(QString()); - } - QCOMPARE(model.rowCount(), itemCount); - QCOMPARE(proxy.rowCount(), itemCount); -} - -QTEST_MAIN(tst_QSortFilterProxyModel) - -#include "tst_qsortfilterproxymodel.moc" 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" diff --git a/tests/benchmarks/corelib/mimetypes/qmimedatabase/CMakeLists.txt b/tests/benchmarks/corelib/mimetypes/qmimedatabase/CMakeLists.txt index 7adc043639..9bddaf57bc 100644 --- a/tests/benchmarks/corelib/mimetypes/qmimedatabase/CMakeLists.txt +++ b/tests/benchmarks/corelib/mimetypes/qmimedatabase/CMakeLists.txt @@ -1,12 +1,10 @@ -# Generated from qmimedatabase.pro. - ##################################################################### ## tst_bench_qmimedatabase Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qmimedatabase SOURCES - main.cpp + tst_bench_qmimedatabase.cpp PUBLIC_LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/mimetypes/qmimedatabase/main.cpp b/tests/benchmarks/corelib/mimetypes/qmimedatabase/main.cpp deleted file mode 100644 index 900e7028a4..0000000000 --- a/tests/benchmarks/corelib/mimetypes/qmimedatabase/main.cpp +++ /dev/null @@ -1,86 +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_QMimeDatabase: public QObject -{ - - Q_OBJECT - -private slots: - void inheritsPerformance(); - void benchMimeTypeForName(); -}; - -void tst_QMimeDatabase::inheritsPerformance() -{ - // Check performance of inherits(). - // This benchmark (which started in 2009 in kmimetypetest.cpp) uses 40 mimetypes. - QStringList mimeTypes; - mimeTypes << QLatin1String("image/jpeg") << QLatin1String("image/png") << QLatin1String("image/tiff") << QLatin1String("text/plain") << QLatin1String("text/html"); - mimeTypes += mimeTypes; - mimeTypes += mimeTypes; - mimeTypes += mimeTypes; - QCOMPARE(mimeTypes.count(), 40); - QMimeDatabase db; - QMimeType mime = db.mimeTypeForName(QString::fromLatin1("text/x-chdr")); - QVERIFY(mime.isValid()); - QBENCHMARK { - QString match; - foreach (const QString &mt, mimeTypes) { - if (mime.inherits(mt)) { - match = mt; - // of course there would normally be a "break" here, but we're testing worse-case - // performance here - } - } - QCOMPARE(match, QString::fromLatin1("text/plain")); - } - // Numbers from 2011, in release mode: - // KDE 4.7 numbers: 0.21 msec / 494,000 ticks / 568,345 instr. loads per iteration - // QMimeBinaryProvider (with Qt 5): 0.16 msec / NA / 416,049 instr. reads per iteration - // QMimeXmlProvider (with Qt 5): 0.062 msec / NA / 172,889 instr. reads per iteration - // (but the startup time is way higher) - // And memory usage is flat at 200K with QMimeBinaryProvider, while it peaks at 6 MB when - // parsing XML, and then keeps being around 4.5 MB for all the in-memory hashes. -} - -void tst_QMimeDatabase::benchMimeTypeForName() -{ - QMimeDatabase db; - - QBENCHMARK { - const auto s = db.mimeTypeForName(QStringLiteral("text/plain")); - QVERIFY(s.isValid()); - } -} - -QTEST_MAIN(tst_QMimeDatabase) -#include "main.moc" diff --git a/tests/benchmarks/corelib/mimetypes/qmimedatabase/tst_bench_qmimedatabase.cpp b/tests/benchmarks/corelib/mimetypes/qmimedatabase/tst_bench_qmimedatabase.cpp new file mode 100644 index 0000000000..fb2a500982 --- /dev/null +++ b/tests/benchmarks/corelib/mimetypes/qmimedatabase/tst_bench_qmimedatabase.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** 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_QMimeDatabase: public QObject +{ + + Q_OBJECT + +private slots: + void inheritsPerformance(); + void benchMimeTypeForName(); +}; + +void tst_QMimeDatabase::inheritsPerformance() +{ + // Check performance of inherits(). + // This benchmark (which started in 2009 in kmimetypetest.cpp) uses 40 mimetypes. + QStringList mimeTypes; + mimeTypes << QLatin1String("image/jpeg") << QLatin1String("image/png") << QLatin1String("image/tiff") << QLatin1String("text/plain") << QLatin1String("text/html"); + mimeTypes += mimeTypes; + mimeTypes += mimeTypes; + mimeTypes += mimeTypes; + QCOMPARE(mimeTypes.count(), 40); + QMimeDatabase db; + QMimeType mime = db.mimeTypeForName(QString::fromLatin1("text/x-chdr")); + QVERIFY(mime.isValid()); + QBENCHMARK { + QString match; + foreach (const QString &mt, mimeTypes) { + if (mime.inherits(mt)) { + match = mt; + // of course there would normally be a "break" here, but we're testing worse-case + // performance here + } + } + QCOMPARE(match, QString::fromLatin1("text/plain")); + } + // Numbers from 2011, in release mode: + // KDE 4.7 numbers: 0.21 msec / 494,000 ticks / 568,345 instr. loads per iteration + // QMimeBinaryProvider (with Qt 5): 0.16 msec / NA / 416,049 instr. reads per iteration + // QMimeXmlProvider (with Qt 5): 0.062 msec / NA / 172,889 instr. reads per iteration + // (but the startup time is way higher) + // And memory usage is flat at 200K with QMimeBinaryProvider, while it peaks at 6 MB when + // parsing XML, and then keeps being around 4.5 MB for all the in-memory hashes. +} + +void tst_QMimeDatabase::benchMimeTypeForName() +{ + QMimeDatabase db; + + QBENCHMARK { + const auto s = db.mimeTypeForName(QStringLiteral("text/plain")); + QVERIFY(s.isValid()); + } +} + +QTEST_MAIN(tst_QMimeDatabase) + +#include "tst_bench_qmimedatabase.moc" diff --git a/tests/benchmarks/corelib/plugin/quuid/CMakeLists.txt b/tests/benchmarks/corelib/plugin/quuid/CMakeLists.txt index 3b787dc8e8..66ec60effc 100644 --- a/tests/benchmarks/corelib/plugin/quuid/CMakeLists.txt +++ b/tests/benchmarks/corelib/plugin/quuid/CMakeLists.txt @@ -1,15 +1,10 @@ -# Generated from quuid.pro. - ##################################################################### ## tst_bench_quuid Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_quuid SOURCES - tst_quuid.cpp + tst_bench_quuid.cpp PUBLIC_LIBRARIES Qt::Test ) - -#### Keys ignored in scope 1:.:.:quuid.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/plugin/quuid/tst_bench_quuid.cpp b/tests/benchmarks/corelib/plugin/quuid/tst_bench_quuid.cpp new file mode 100644 index 0000000000..2db1563568 --- /dev/null +++ b/tests/benchmarks/corelib/plugin/quuid/tst_bench_quuid.cpp @@ -0,0 +1,197 @@ +/**************************************************************************** +** +** 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 tst_QUuid : public QObject +{ + Q_OBJECT + +private slots: + void createUuid(); + void fromChar(); + void toString(); + void fromString(); + void toByteArray(); + void fromByteArray(); + void toRfc4122(); + void fromRfc4122(); + void createUuidV3(); + void createUuidV5(); + void toDataStream(); + void fromDataStream(); + void isNull(); + void operatorLess(); + void operatorMore(); +}; + +void tst_QUuid::createUuid() +{ + QBENCHMARK { + QUuid::createUuid(); + } +} + +void tst_QUuid::fromChar() +{ + QBENCHMARK { + QUuid uuid("{67C8770B-44F1-410A-AB9A-F9B5446F13EE}"); + } +} + +void tst_QUuid::toString() +{ + QUuid uuid = QUuid::createUuid(); + QBENCHMARK { + uuid.toString(); + } +} + +void tst_QUuid::fromString() +{ + QString string = "{67C8770B-44F1-410A-AB9A-F9B5446F13EE}"; + QBENCHMARK { + QUuid uuid(string); + } +} + +void tst_QUuid::toByteArray() +{ + QUuid uuid = QUuid::createUuid(); + QBENCHMARK { + uuid.toByteArray(); + } +} + +void tst_QUuid::fromByteArray() +{ + QByteArray string = "{67C8770B-44F1-410A-AB9A-F9B5446F13EE}"; + QBENCHMARK { + QUuid uuid(string); + } +} + +void tst_QUuid::toRfc4122() +{ + QUuid uuid = QUuid::createUuid(); + QBENCHMARK { + uuid.toRfc4122(); + } +} + +void tst_QUuid::fromRfc4122() +{ + QByteArray string = QByteArray::fromHex("67C8770B44F1410AAB9AF9B5446F13EE"); + QBENCHMARK { + QUuid uuid = QUuid::fromRfc4122(string); + Q_UNUSED(uuid) + } +} + +void tst_QUuid::createUuidV3() +{ + QUuid ns = QUuid::createUuid(); + QByteArray name = QByteArray("Test"); + QBENCHMARK { + QUuid uuid = QUuid::createUuidV3(ns, name); + Q_UNUSED(uuid) + } +} + +void tst_QUuid::createUuidV5() +{ + QUuid ns = QUuid::createUuid(); + QByteArray name = QByteArray("Test"); + QBENCHMARK { + QUuid uuid = QUuid::createUuidV5(ns, name); + Q_UNUSED(uuid) + } +} + +void tst_QUuid::toDataStream() +{ + QUuid uuid = QUuid::createUuid(); + QByteArray ar; + { + QDataStream out(&ar,QIODevice::WriteOnly); + QBENCHMARK { + out << uuid; + } + } +} + +void tst_QUuid::fromDataStream() +{ + QUuid uuid1, uuid2; + uuid1 = QUuid::createUuid(); + QByteArray ar; + { + QDataStream out(&ar,QIODevice::WriteOnly); + out << uuid1; + } + { + QDataStream in(&ar,QIODevice::ReadOnly); + QBENCHMARK { + in >> uuid2; + } + } +} + +void tst_QUuid::isNull() +{ + QUuid uuid = QUuid(); + QBENCHMARK { + uuid.isNull(); + } +} + +void tst_QUuid::operatorLess() +{ + QUuid uuid1, uuid2; + uuid1 = QUuid::createUuid(); + uuid2 = QUuid::createUuid(); + QBENCHMARK { + uuid1 < uuid2; + } +} + +void tst_QUuid::operatorMore() +{ + QUuid uuid1, uuid2; + uuid1 = QUuid::createUuid(); + uuid2 = QUuid::createUuid(); + QBENCHMARK { + uuid1 > uuid2; + } +} + +QTEST_MAIN(tst_QUuid) + +#include "tst_bench_quuid.moc" diff --git a/tests/benchmarks/corelib/plugin/quuid/tst_quuid.cpp b/tests/benchmarks/corelib/plugin/quuid/tst_quuid.cpp deleted file mode 100644 index 0bc0a7de93..0000000000 --- a/tests/benchmarks/corelib/plugin/quuid/tst_quuid.cpp +++ /dev/null @@ -1,200 +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 tst_bench_QUuid : public QObject -{ - Q_OBJECT - -public: - tst_bench_QUuid() - { } - -private slots: - void createUuid(); - void fromChar(); - void toString(); - void fromString(); - void toByteArray(); - void fromByteArray(); - void toRfc4122(); - void fromRfc4122(); - void createUuidV3(); - void createUuidV5(); - void toDataStream(); - void fromDataStream(); - void isNull(); - void operatorLess(); - void operatorMore(); -}; - -void tst_bench_QUuid::createUuid() -{ - QBENCHMARK { - QUuid::createUuid(); - } -} - -void tst_bench_QUuid::fromChar() -{ - QBENCHMARK { - QUuid uuid("{67C8770B-44F1-410A-AB9A-F9B5446F13EE}"); - } -} - -void tst_bench_QUuid::toString() -{ - QUuid uuid = QUuid::createUuid(); - QBENCHMARK { - uuid.toString(); - } -} - -void tst_bench_QUuid::fromString() -{ - QString string = "{67C8770B-44F1-410A-AB9A-F9B5446F13EE}"; - QBENCHMARK { - QUuid uuid(string); - } -} - -void tst_bench_QUuid::toByteArray() -{ - QUuid uuid = QUuid::createUuid(); - QBENCHMARK { - uuid.toByteArray(); - } -} - -void tst_bench_QUuid::fromByteArray() -{ - QByteArray string = "{67C8770B-44F1-410A-AB9A-F9B5446F13EE}"; - QBENCHMARK { - QUuid uuid(string); - } -} - -void tst_bench_QUuid::toRfc4122() -{ - QUuid uuid = QUuid::createUuid(); - QBENCHMARK { - uuid.toRfc4122(); - } -} - -void tst_bench_QUuid::fromRfc4122() -{ - QByteArray string = QByteArray::fromHex("67C8770B44F1410AAB9AF9B5446F13EE"); - QBENCHMARK { - QUuid uuid = QUuid::fromRfc4122(string); - Q_UNUSED(uuid) - } -} - -void tst_bench_QUuid::createUuidV3() -{ - QUuid ns = QUuid::createUuid(); - QByteArray name = QByteArray("Test"); - QBENCHMARK { - QUuid uuid = QUuid::createUuidV3(ns, name); - Q_UNUSED(uuid) - } -} - -void tst_bench_QUuid::createUuidV5() -{ - QUuid ns = QUuid::createUuid(); - QByteArray name = QByteArray("Test"); - QBENCHMARK { - QUuid uuid = QUuid::createUuidV5(ns, name); - Q_UNUSED(uuid) - } -} - -void tst_bench_QUuid::toDataStream() -{ - QUuid uuid = QUuid::createUuid(); - QByteArray ar; - { - QDataStream out(&ar,QIODevice::WriteOnly); - QBENCHMARK { - out << uuid; - } - } -} - -void tst_bench_QUuid::fromDataStream() -{ - QUuid uuid1, uuid2; - uuid1 = QUuid::createUuid(); - QByteArray ar; - { - QDataStream out(&ar,QIODevice::WriteOnly); - out << uuid1; - } - { - QDataStream in(&ar,QIODevice::ReadOnly); - QBENCHMARK { - in >> uuid2; - } - } -} - -void tst_bench_QUuid::isNull() -{ - QUuid uuid = QUuid(); - QBENCHMARK { - uuid.isNull(); - } -} - -void tst_bench_QUuid::operatorLess() -{ - QUuid uuid1, uuid2; - uuid1 = QUuid::createUuid(); - uuid2 = QUuid::createUuid(); - QBENCHMARK { - uuid1 < uuid2; - } -} - -void tst_bench_QUuid::operatorMore() -{ - QUuid uuid1, uuid2; - uuid1 = QUuid::createUuid(); - uuid2 = QUuid::createUuid(); - QBENCHMARK { - uuid1 > uuid2; - } -} - -QTEST_MAIN(tst_bench_QUuid); -#include "tst_quuid.moc" diff --git a/tests/benchmarks/corelib/text/qbytearray/CMakeLists.txt b/tests/benchmarks/corelib/text/qbytearray/CMakeLists.txt index 50574aa221..18b811501b 100644 --- a/tests/benchmarks/corelib/text/qbytearray/CMakeLists.txt +++ b/tests/benchmarks/corelib/text/qbytearray/CMakeLists.txt @@ -1,16 +1,10 @@ -# Generated from qbytearray.pro. - ##################################################################### ## tst_bench_qbytearray Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qbytearray SOURCES - main.cpp + tst_bench_qbytearray.cpp PUBLIC_LIBRARIES Qt::Test ) - -#### Keys ignored in scope 1:.:.:qbytearray.pro:: -# TEMPLATE = "app" -# TESTDATA = "main.cpp" diff --git a/tests/benchmarks/corelib/text/qbytearray/main.cpp b/tests/benchmarks/corelib/text/qbytearray/main.cpp deleted file mode 100644 index 43151041d0..0000000000 --- a/tests/benchmarks/corelib/text/qbytearray/main.cpp +++ /dev/null @@ -1,384 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Copyright (C) 2016 Intel Corporation. -** 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 - - -class tst_qbytearray : public QObject -{ - Q_OBJECT - QByteArray sourcecode; -private slots: - void initTestCase(); - void append(); - void append_data(); - - void toLongLong_data(); - void toLongLong(); - void toULongLong_data(); - void toULongLong(); - - void latin1Uppercasing_qt54(); - void latin1Uppercasing_xlate(); - void latin1Uppercasing_xlate_checked(); - void latin1Uppercasing_category(); - void latin1Uppercasing_bitcheck(); - - void toPercentEncoding_data(); - void toPercentEncoding(); -}; - -void tst_qbytearray::initTestCase() -{ - QFile self(QFINDTESTDATA("main.cpp")); - QVERIFY(self.open(QIODevice::ReadOnly)); - sourcecode = self.readAll(); -} - -void tst_qbytearray::append_data() -{ - QTest::addColumn("size"); - QTest::newRow("1") << int(1); - QTest::newRow("10") << int(10); - QTest::newRow("100") << int(100); - QTest::newRow("1000") << int(1000); - QTest::newRow("10000") << int(10000); - QTest::newRow("100000") << int(100000); - QTest::newRow("1000000") << int(1000000); - QTest::newRow("10000000") << int(10000000); - QTest::newRow("100000000") << int(100000000); -} - -void tst_qbytearray::append() -{ - QFETCH(int, size); - - QByteArray ba; - QBENCHMARK { - QByteArray ba2(size, 'x'); - ba.append(ba2); - ba.clear(); - } -} - -static QByteArray decNext(QByteArray &&big) -{ - // Increments a decimal digit-string (ignoring sign, so decrements if - // negative); only intended for taking a boundary value just out of range, - // so big is never a string of only 9s (that'd be one less than a power of - // ten, which cannot be a power of two, as odd, or one less than one, as the - // power of ten isn't a power of two). - int i = big.size() - 1; - while (big.at(i) == '9') - big[i--] = '0'; - big[i] += 1; - return big; -} - -void tst_qbytearray::toLongLong_data() -{ - QTest::addColumn("text"); - QTest::addColumn("good"); - QTest::addColumn("number"); -#define ROW(n) QTest::newRow(#n) << QByteArray(#n) << true << n ## LL - ROW(0); - ROW(1); - ROW(-1); - ROW(17); - ROW(-17); - ROW(1234567890); - ROW(-1234567890); -#undef ROW - using LL = std::numeric_limits; - QTest::newRow("min") << QByteArray::number(LL::min()) << true << LL::min(); - QTest::newRow("min-1") << decNext(QByteArray::number(LL::min())) << false << 0LL; - QTest::newRow("max") << QByteArray::number(LL::max()) << true << LL::max(); - QTest::newRow("max+1") << decNext(QByteArray::number(LL::max())) << false << 0LL; -} - -void tst_qbytearray::toLongLong() -{ - QFETCH(QByteArray, text); - QFETCH(bool, good); - QFETCH(qlonglong, number); - - qlonglong actual = 0; - bool ok; - QBENCHMARK { - actual = text.toLongLong(&ok); - } - QCOMPARE(actual, number); - QCOMPARE(ok, good); -} - -void tst_qbytearray::toULongLong_data() -{ - QTest::addColumn("text"); - QTest::addColumn("good"); - QTest::addColumn("number"); -#define ROW(n) \ - QTest::newRow(#n) << QByteArray(#n) << true << n ## ULL; \ - QTest::newRow("-" #n) << QByteArray("-" #n) << false << 0ULL - ROW(0); - ROW(1); - ROW(17); - ROW(1234567890); -#undef ROW - using ULL = std::numeric_limits; - QTest::newRow("max") << QByteArray::number(ULL::max()) << true << ULL::max(); - QTest::newRow("max+1") << decNext(QByteArray::number(ULL::max())) << false << 0ULL; -} - -void tst_qbytearray::toULongLong() -{ - QFETCH(QByteArray, text); - QFETCH(bool, good); - QFETCH(qulonglong, number); - - qulonglong actual = 0; - bool ok; - QBENCHMARK { - actual = text.toULongLong(&ok); - } - QCOMPARE(actual, number); - QCOMPARE(ok, good); -} - -void tst_qbytearray::latin1Uppercasing_qt54() -{ - QByteArray s = sourcecode; - s.detach(); - - // the following was copied from qbytearray.cpp (except for the QBENCHMARK macro): - uchar *p_orig = reinterpret_cast(s.data()); - uchar *e = reinterpret_cast(s.end()); - - QBENCHMARK { - uchar *p = p_orig; - if (p) { - while (p != e) { - *p = QChar::toLower((ushort)*p); - p++; - } - } - } -} - - -/* -#!/usr/bin/perl -l -use feature "unicode_strings" -for (0..255) { - $up = uc(chr($_)); - $up = chr($_) if ord($up) > 0x100 || length $up > 1; - printf "0x%02x,", ord($up); - print "" if ($_ & 0xf) == 0xf; -} -*/ -static const uchar uppercased[256] = { - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, - 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f, - 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f, - 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f, - 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f, - 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f, - 0x60,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f, - 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x7b,0x7c,0x7d,0x7e,0x7f, - 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, - 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, - 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf, - 0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf, - 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf, - 0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf, - 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf, - 0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xf7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xff -}; -void tst_qbytearray::latin1Uppercasing_xlate() -{ - QByteArray output = sourcecode; - output.detach(); - char *dst_orig = output.data(); - const char *src_orig = sourcecode.constBegin(); - const char *end = sourcecode.constEnd(); - QBENCHMARK { - char *dst = dst_orig; - for (const char *src = src_orig; src != end; ++src, ++dst) - *dst = uppercased[uchar(*src)]; - } -} - -void tst_qbytearray::latin1Uppercasing_xlate_checked() -{ - QByteArray output = sourcecode; - output.detach(); - char *dst_orig = output.data(); - const char *src_orig = sourcecode.constBegin(); - const char *end = sourcecode.constEnd(); - QBENCHMARK { - char *dst = dst_orig; - for (const char *src = src_orig; src != end; ++src, ++dst) { - uchar ch = uchar(*src); - uchar converted = uppercased[ch]; - if (ch != converted) - *dst = converted; - } - } -} - -/* -#!/bin/perl -l -use feature "unicode_strings"; -sub categorize($) { - # 'ß' and 'ÿ' are lowercase, but we cannot uppercase them - return 0 if $_[0] == 0xDF || $_[0] == 0xFF; - $ch = chr($_[0]); - return 2 if uc($ch) ne $ch; - return 1 if lc($ch) ne $ch; - return 0; -} -for (0..255) { - printf "%d,", categorize($_); - print "" if ($_ & 0xf) == 0xf; -} -*/ -static const char categories[256] = { - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, - 0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,0,2,2,2,2,2,2,2,0 -}; - -void tst_qbytearray::latin1Uppercasing_category() -{ - QByteArray output = sourcecode; - output.detach(); - char *dst_orig = output.data(); - const char *src_orig = sourcecode.constBegin(); - const char *end = sourcecode.constEnd(); - QBENCHMARK { - char *dst = dst_orig; - for (const char *src = src_orig; src != end; ++src, ++dst) - *dst = categories[uchar(*src)] == 1 ? *src & ~0x20 : *src; - } -} - -/* -#!/bin/perl -l -use feature "unicode_strings"; -sub categorize($) { - # 'ß' and 'ÿ' are lowercase, but we cannot uppercase them - return 0 if $_[0] == 0xDF || $_[0] == 0xFF; - $ch = chr($_[0]); - return 2 if uc($ch) ne $ch; - return 1 if lc($ch) ne $ch; - return 0; -} -for $row (0..7) { - $val = 0; - for $col (0..31) { - $val |= (1<<$col) - if categorize($row * 31 + $col) == 2; - } - printf "0x%08x,", $val; -} -*/ - -static const quint32 shouldUppercase[8] = { - 0x00000000,0x00000000,0x00000000,0x3ffffff0,0x00000000,0x04000000,0x00000000,0xbfffff80 -}; - -static bool bittest(const quint32 *data, uchar bit) -{ - static const unsigned bitsperelem = sizeof(*data) * CHAR_BIT; - return data[bit / bitsperelem] & (1 << (bit & (bitsperelem - 1))); -} - -void tst_qbytearray::latin1Uppercasing_bitcheck() -{ - QByteArray output = sourcecode; - output.detach(); - char *dst_orig = output.data(); - const char *src_orig = sourcecode.constBegin(); - const char *end = sourcecode.constEnd(); - QBENCHMARK { - char *dst = dst_orig; - for (const char *src = src_orig; src != end; ++src, ++dst) - *dst = bittest(shouldUppercase, *src) ? uchar(*src) & ~0x20 : uchar(*src); - } -} - -void tst_qbytearray::toPercentEncoding_data() -{ - QTest::addColumn("plaintext"); - QTest::addColumn("expected"); - - QTest::newRow("empty") << QByteArray("") << QByteArray(""); - QTest::newRow("plain") - << QByteArray("the quick brown fox jumped over the lazy dogs") - << QByteArray("the%20quick%20brown%20fox%20jumped%20over%20the%20lazy%20dogs"); - QTest::newRow("specials") - << QByteArray( - "\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15" - "\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,/:;<=>?@[\\]^`{|}\x7f") - << QByteArray( - "%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18" - "%19%1A%1B%1C%1D%1E%1F%20%21%22%23%24%25%26%27%28%29%2A%2B%2C%2F%3A%3B%3C" - "%3D%3E%3F%40%5B%5C%5D%5E%60%7B%7C%7D%7F"); -} - -void tst_qbytearray::toPercentEncoding() -{ - QFETCH(QByteArray, plaintext); - QByteArray encoded; - QBENCHMARK { - encoded = plaintext.toPercentEncoding(); - } - QTEST(encoded, "expected"); -} - -QTEST_MAIN(tst_qbytearray) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/text/qbytearray/tst_bench_qbytearray.cpp b/tests/benchmarks/corelib/text/qbytearray/tst_bench_qbytearray.cpp new file mode 100644 index 0000000000..01ee46c53e --- /dev/null +++ b/tests/benchmarks/corelib/text/qbytearray/tst_bench_qbytearray.cpp @@ -0,0 +1,383 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Copyright (C) 2016 Intel Corporation. +** 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 + +class tst_QByteArray : public QObject +{ + Q_OBJECT + QByteArray sourcecode; +private slots: + void initTestCase(); + void append(); + void append_data(); + + void toLongLong_data(); + void toLongLong(); + void toULongLong_data(); + void toULongLong(); + + void latin1Uppercasing_qt54(); + void latin1Uppercasing_xlate(); + void latin1Uppercasing_xlate_checked(); + void latin1Uppercasing_category(); + void latin1Uppercasing_bitcheck(); + + void toPercentEncoding_data(); + void toPercentEncoding(); +}; + +void tst_QByteArray::initTestCase() +{ + QFile self(QFINDTESTDATA("tst_bench_qbytearray.cpp")); + QVERIFY(self.open(QIODevice::ReadOnly)); + sourcecode = self.readAll(); +} + +void tst_QByteArray::append_data() +{ + QTest::addColumn("size"); + QTest::newRow("1") << int(1); + QTest::newRow("10") << int(10); + QTest::newRow("100") << int(100); + QTest::newRow("1000") << int(1000); + QTest::newRow("10000") << int(10000); + QTest::newRow("100000") << int(100000); + QTest::newRow("1000000") << int(1000000); + QTest::newRow("10000000") << int(10000000); + QTest::newRow("100000000") << int(100000000); +} + +void tst_QByteArray::append() +{ + QFETCH(int, size); + + QByteArray ba; + QBENCHMARK { + QByteArray ba2(size, 'x'); + ba.append(ba2); + ba.clear(); + } +} + +static QByteArray decNext(QByteArray &&big) +{ + // Increments a decimal digit-string (ignoring sign, so decrements if + // negative); only intended for taking a boundary value just out of range, + // so big is never a string of only 9s (that'd be one less than a power of + // ten, which cannot be a power of two, as odd, or one less than one, as the + // power of ten isn't a power of two). + int i = big.size() - 1; + while (big.at(i) == '9') + big[i--] = '0'; + big[i] += 1; + return big; +} + +void tst_QByteArray::toLongLong_data() +{ + QTest::addColumn("text"); + QTest::addColumn("good"); + QTest::addColumn("number"); +#define ROW(n) QTest::newRow(#n) << QByteArray(#n) << true << n ## LL + ROW(0); + ROW(1); + ROW(-1); + ROW(17); + ROW(-17); + ROW(1234567890); + ROW(-1234567890); +#undef ROW + using LL = std::numeric_limits; + QTest::newRow("min") << QByteArray::number(LL::min()) << true << LL::min(); + QTest::newRow("min-1") << decNext(QByteArray::number(LL::min())) << false << 0LL; + QTest::newRow("max") << QByteArray::number(LL::max()) << true << LL::max(); + QTest::newRow("max+1") << decNext(QByteArray::number(LL::max())) << false << 0LL; +} + +void tst_QByteArray::toLongLong() +{ + QFETCH(QByteArray, text); + QFETCH(bool, good); + QFETCH(qlonglong, number); + + qlonglong actual = 0; + bool ok; + QBENCHMARK { + actual = text.toLongLong(&ok); + } + QCOMPARE(actual, number); + QCOMPARE(ok, good); +} + +void tst_QByteArray::toULongLong_data() +{ + QTest::addColumn("text"); + QTest::addColumn("good"); + QTest::addColumn("number"); +#define ROW(n) \ + QTest::newRow(#n) << QByteArray(#n) << true << n ## ULL; \ + QTest::newRow("-" #n) << QByteArray("-" #n) << false << 0ULL + ROW(0); + ROW(1); + ROW(17); + ROW(1234567890); +#undef ROW + using ULL = std::numeric_limits; + QTest::newRow("max") << QByteArray::number(ULL::max()) << true << ULL::max(); + QTest::newRow("max+1") << decNext(QByteArray::number(ULL::max())) << false << 0ULL; +} + +void tst_QByteArray::toULongLong() +{ + QFETCH(QByteArray, text); + QFETCH(bool, good); + QFETCH(qulonglong, number); + + qulonglong actual = 0; + bool ok; + QBENCHMARK { + actual = text.toULongLong(&ok); + } + QCOMPARE(actual, number); + QCOMPARE(ok, good); +} + +void tst_QByteArray::latin1Uppercasing_qt54() +{ + QByteArray s = sourcecode; + s.detach(); + + // the following was copied from qbytearray.cpp (except for the QBENCHMARK macro): + uchar *p_orig = reinterpret_cast(s.data()); + uchar *e = reinterpret_cast(s.end()); + + QBENCHMARK { + uchar *p = p_orig; + if (p) { + while (p != e) { + *p = QChar::toLower((ushort)*p); + p++; + } + } + } +} + + +/* +#!/usr/bin/perl -l +use feature "unicode_strings" +for (0..255) { + $up = uc(chr($_)); + $up = chr($_) if ord($up) > 0x100 || length $up > 1; + printf "0x%02x,", ord($up); + print "" if ($_ & 0xf) == 0xf; +} +*/ +static const uchar uppercased[256] = { + 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, + 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f, + 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f, + 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f, + 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f, + 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f, + 0x60,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f, + 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x7b,0x7c,0x7d,0x7e,0x7f, + 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, + 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, + 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf, + 0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf, + 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf, + 0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf, + 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf, + 0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xf7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xff +}; +void tst_QByteArray::latin1Uppercasing_xlate() +{ + QByteArray output = sourcecode; + output.detach(); + char *dst_orig = output.data(); + const char *src_orig = sourcecode.constBegin(); + const char *end = sourcecode.constEnd(); + QBENCHMARK { + char *dst = dst_orig; + for (const char *src = src_orig; src != end; ++src, ++dst) + *dst = uppercased[uchar(*src)]; + } +} + +void tst_QByteArray::latin1Uppercasing_xlate_checked() +{ + QByteArray output = sourcecode; + output.detach(); + char *dst_orig = output.data(); + const char *src_orig = sourcecode.constBegin(); + const char *end = sourcecode.constEnd(); + QBENCHMARK { + char *dst = dst_orig; + for (const char *src = src_orig; src != end; ++src, ++dst) { + uchar ch = uchar(*src); + uchar converted = uppercased[ch]; + if (ch != converted) + *dst = converted; + } + } +} + +/* +#!/bin/perl -l +use feature "unicode_strings"; +sub categorize($) { + # 'ß' and 'ÿ' are lowercase, but we cannot uppercase them + return 0 if $_[0] == 0xDF || $_[0] == 0xFF; + $ch = chr($_[0]); + return 2 if uc($ch) ne $ch; + return 1 if lc($ch) ne $ch; + return 0; +} +for (0..255) { + printf "%d,", categorize($_); + print "" if ($_ & 0xf) == 0xf; +} +*/ +static const char categories[256] = { + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, + 0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, + 0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0, + 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, + 1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0, + 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, + 2,2,2,2,2,2,2,0,2,2,2,2,2,2,2,0 +}; + +void tst_QByteArray::latin1Uppercasing_category() +{ + QByteArray output = sourcecode; + output.detach(); + char *dst_orig = output.data(); + const char *src_orig = sourcecode.constBegin(); + const char *end = sourcecode.constEnd(); + QBENCHMARK { + char *dst = dst_orig; + for (const char *src = src_orig; src != end; ++src, ++dst) + *dst = categories[uchar(*src)] == 1 ? *src & ~0x20 : *src; + } +} + +/* +#!/bin/perl -l +use feature "unicode_strings"; +sub categorize($) { + # 'ß' and 'ÿ' are lowercase, but we cannot uppercase them + return 0 if $_[0] == 0xDF || $_[0] == 0xFF; + $ch = chr($_[0]); + return 2 if uc($ch) ne $ch; + return 1 if lc($ch) ne $ch; + return 0; +} +for $row (0..7) { + $val = 0; + for $col (0..31) { + $val |= (1<<$col) + if categorize($row * 31 + $col) == 2; + } + printf "0x%08x,", $val; +} +*/ + +static const quint32 shouldUppercase[8] = { + 0x00000000,0x00000000,0x00000000,0x3ffffff0,0x00000000,0x04000000,0x00000000,0xbfffff80 +}; + +static bool bittest(const quint32 *data, uchar bit) +{ + static const unsigned bitsperelem = sizeof(*data) * CHAR_BIT; + return data[bit / bitsperelem] & (1 << (bit & (bitsperelem - 1))); +} + +void tst_QByteArray::latin1Uppercasing_bitcheck() +{ + QByteArray output = sourcecode; + output.detach(); + char *dst_orig = output.data(); + const char *src_orig = sourcecode.constBegin(); + const char *end = sourcecode.constEnd(); + QBENCHMARK { + char *dst = dst_orig; + for (const char *src = src_orig; src != end; ++src, ++dst) + *dst = bittest(shouldUppercase, *src) ? uchar(*src) & ~0x20 : uchar(*src); + } +} + +void tst_QByteArray::toPercentEncoding_data() +{ + QTest::addColumn("plaintext"); + QTest::addColumn("expected"); + + QTest::newRow("empty") << QByteArray("") << QByteArray(""); + QTest::newRow("plain") + << QByteArray("the quick brown fox jumped over the lazy dogs") + << QByteArray("the%20quick%20brown%20fox%20jumped%20over%20the%20lazy%20dogs"); + QTest::newRow("specials") + << QByteArray( + "\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15" + "\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !\"#$%&'()*+,/:;<=>?@[\\]^`{|}\x7f") + << QByteArray( + "%01%02%03%04%05%06%07%08%09%0A%0B%0C%0D%0E%0F%10%11%12%13%14%15%16%17%18" + "%19%1A%1B%1C%1D%1E%1F%20%21%22%23%24%25%26%27%28%29%2A%2B%2C%2F%3A%3B%3C" + "%3D%3E%3F%40%5B%5C%5D%5E%60%7B%7C%7D%7F"); +} + +void tst_QByteArray::toPercentEncoding() +{ + QFETCH(QByteArray, plaintext); + QByteArray encoded; + QBENCHMARK { + encoded = plaintext.toPercentEncoding(); + } + QTEST(encoded, "expected"); +} + +QTEST_MAIN(tst_QByteArray) + +#include "tst_bench_qbytearray.moc" diff --git a/tests/benchmarks/corelib/text/qchar/CMakeLists.txt b/tests/benchmarks/corelib/text/qchar/CMakeLists.txt index afdf96e9d4..ef7f553f2e 100644 --- a/tests/benchmarks/corelib/text/qchar/CMakeLists.txt +++ b/tests/benchmarks/corelib/text/qchar/CMakeLists.txt @@ -1,12 +1,10 @@ -# Generated from qchar.pro. - ##################################################################### ## tst_bench_qchar Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qchar SOURCES - main.cpp + tst_bench_qchar.cpp PUBLIC_LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/text/qchar/main.cpp b/tests/benchmarks/corelib/text/qchar/main.cpp deleted file mode 100644 index 746f9730f7..0000000000 --- a/tests/benchmarks/corelib/text/qchar/main.cpp +++ /dev/null @@ -1,136 +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_QChar: public QObject -{ - Q_OBJECT -private slots: - void isUpper_data(); - void isUpper(); - void isLower_data(); - void isLower(); - void isLetter_data(); - void isLetter(); - void isDigit_data(); - void isDigit(); - void isLetterOrNumber_data(); - void isLetterOrNumber(); - void isSpace_data(); - void isSpace(); -}; - -void tst_QChar::isUpper_data() -{ - QTest::addColumn("c"); - - QTest::newRow("k") << QChar('k'); - QTest::newRow("K") << QChar('K'); - QTest::newRow("5") << QChar('5'); - QTest::newRow("\\0") << QChar(); - QTest::newRow("space") << QChar(' '); - QTest::newRow("\\u3C20") << QChar(0x3C20); -} - -void tst_QChar::isUpper() -{ - QFETCH(QChar, c); - QBENCHMARK { - c.isUpper(); - } -} - -void tst_QChar::isLower_data() -{ - isUpper_data(); -} - -void tst_QChar::isLower() -{ - QFETCH(QChar, c); - QBENCHMARK { - c.isLower(); - } -} - -void tst_QChar::isLetter_data() -{ - isUpper_data(); -} - -void tst_QChar::isLetter() -{ - QFETCH(QChar, c); - QBENCHMARK { - c.isLetter(); - } -} - -void tst_QChar::isDigit_data() -{ - isUpper_data(); -} - -void tst_QChar::isDigit() -{ - QFETCH(QChar, c); - QBENCHMARK { - c.isDigit(); - } -} - -void tst_QChar::isLetterOrNumber_data() -{ - isUpper_data(); -} - -void tst_QChar::isLetterOrNumber() -{ - QFETCH(QChar, c); - QBENCHMARK { - c.isLetterOrNumber(); - } -} - -void tst_QChar::isSpace_data() -{ - isUpper_data(); -} - -void tst_QChar::isSpace() -{ - QFETCH(QChar, c); - QBENCHMARK { - c.isSpace(); - } -} - -QTEST_MAIN(tst_QChar) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/text/qchar/tst_bench_qchar.cpp b/tests/benchmarks/corelib/text/qchar/tst_bench_qchar.cpp new file mode 100644 index 0000000000..b1adfdca4e --- /dev/null +++ b/tests/benchmarks/corelib/text/qchar/tst_bench_qchar.cpp @@ -0,0 +1,136 @@ +/**************************************************************************** +** +** 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_QChar: public QObject +{ + Q_OBJECT +private slots: + void isUpper_data(); + void isUpper(); + void isLower_data(); + void isLower(); + void isLetter_data(); + void isLetter(); + void isDigit_data(); + void isDigit(); + void isLetterOrNumber_data(); + void isLetterOrNumber(); + void isSpace_data(); + void isSpace(); +}; + +void tst_QChar::isUpper_data() +{ + QTest::addColumn("c"); + + QTest::newRow("k") << QChar('k'); + QTest::newRow("K") << QChar('K'); + QTest::newRow("5") << QChar('5'); + QTest::newRow("\\0") << QChar(); + QTest::newRow("space") << QChar(' '); + QTest::newRow("\\u3C20") << QChar(0x3C20); +} + +void tst_QChar::isUpper() +{ + QFETCH(QChar, c); + QBENCHMARK { + c.isUpper(); + } +} + +void tst_QChar::isLower_data() +{ + isUpper_data(); +} + +void tst_QChar::isLower() +{ + QFETCH(QChar, c); + QBENCHMARK { + c.isLower(); + } +} + +void tst_QChar::isLetter_data() +{ + isUpper_data(); +} + +void tst_QChar::isLetter() +{ + QFETCH(QChar, c); + QBENCHMARK { + c.isLetter(); + } +} + +void tst_QChar::isDigit_data() +{ + isUpper_data(); +} + +void tst_QChar::isDigit() +{ + QFETCH(QChar, c); + QBENCHMARK { + c.isDigit(); + } +} + +void tst_QChar::isLetterOrNumber_data() +{ + isUpper_data(); +} + +void tst_QChar::isLetterOrNumber() +{ + QFETCH(QChar, c); + QBENCHMARK { + c.isLetterOrNumber(); + } +} + +void tst_QChar::isSpace_data() +{ + isUpper_data(); +} + +void tst_QChar::isSpace() +{ + QFETCH(QChar, c); + QBENCHMARK { + c.isSpace(); + } +} + +QTEST_MAIN(tst_QChar) + +#include "tst_bench_qchar.moc" diff --git a/tests/benchmarks/corelib/text/qlocale/CMakeLists.txt b/tests/benchmarks/corelib/text/qlocale/CMakeLists.txt index 1c692af6c8..f319c0b5bd 100644 --- a/tests/benchmarks/corelib/text/qlocale/CMakeLists.txt +++ b/tests/benchmarks/corelib/text/qlocale/CMakeLists.txt @@ -1,12 +1,10 @@ -# Generated from qlocale.pro. - ##################################################################### ## tst_bench_qlocale Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qlocale SOURCES - main.cpp + tst_bench_qlocale.cpp PUBLIC_LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/text/qlocale/main.cpp b/tests/benchmarks/corelib/text/qlocale/main.cpp deleted file mode 100644 index 887053ae4a..0000000000 --- a/tests/benchmarks/corelib/text/qlocale/main.cpp +++ /dev/null @@ -1,397 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module 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_QLocale : public QObject -{ - Q_OBJECT - -private Q_SLOTS: - void fromString_data(); - void fromString(); - void fromTags_data(); - void fromTags(); - void fromLangScript_data(); - void fromLangScript(); - void fromLangLand_data(); - void fromLangLand(); - void fromScriptLand_data(); - void fromScriptLand(); - void fromLang_data(); - void fromLang(); - void fromScript_data(); - void fromScript(); - void fromLand_data(); - void fromLand(); - void toUpper_QLocale_1(); - void toUpper_QLocale_2(); - void toUpper_QString(); - void number_QString(); -}; - -static QString data() -{ - return QStringLiteral("/qt-5/qtbase/tests/benchmarks/corelib/tools/qlocale"); -} - -// Make individual cycles O(a few) msecs, rather than tiny fractions thereof: -#define LOOP(s) for (int i = 0; i < 5000; ++i) { s; } - -void tst_QLocale::fromString_data() -{ - QTest::addColumn("name"); - - QTest::newRow("C") << QStringLiteral("C"); -#define ROW(name) QTest::newRow(name) << QStringLiteral(name) - ROW("en-Latn-DE"); - ROW("sd-Deva-IN"); - ROW("az-Cyrl-AZ"); - ROW("az-Latn-AZ"); - ROW("bs-Cyrl-BA"); - ROW("bs-Latn-BA"); - ROW("ff-Latn-LR"); - ROW("ff-Latn-MR"); - ROW("pa-Arab-PK"); - ROW("pa-Guru-IN"); - ROW("shi-Latn-MA"); - ROW("shi-Tfng-MA"); - ROW("sr-Cyrl-BA"); - ROW("sr-Cyrl-RS"); - ROW("sr-Latn-BA"); - ROW("sr-Latn-ME"); - ROW("uz-Arab-AF"); - ROW("uz-Cyrl-UZ"); - ROW("uz-Latn-UZ"); - ROW("vai-Latn-LR"); - ROW("vai-Vaii-LR"); - ROW("yue-Hans-CN"); - ROW("yue-Hant-HK"); - ROW("zh-Hans-CN"); - ROW("zh-Hans-HK"); - ROW("zh-Hans-SG"); - ROW("zh-Hant-HK"); - ROW("zh-Hant-TW"); -#undef ROW -} - -void tst_QLocale::fromString() -{ - QFETCH(const QString, name); - QBENCHMARK { LOOP(QLocale loc(name)) } -} - -void tst_QLocale::fromTags_data() -{ - QTest::addColumn("language"); - QTest::addColumn("script"); - QTest::addColumn("territory"); - -#define ROW(name, lang, text, land) \ - QTest::newRow(name) << QLocale::lang << QLocale::text << QLocale::land - ROW("C", C, AnyScript, AnyTerritory); - ROW("en-Latn-DE", English, LatinScript, Germany); - ROW("sd-Deva-IN", Sindhi, DevanagariScript, India); - ROW("az-Cyrl-AZ", Azerbaijani, CyrillicScript, Azerbaijan); - ROW("az-Latn-AZ", Azerbaijani, LatinScript, Azerbaijan); - ROW("bs-Cyrl-BA", Bosnian, CyrillicScript, BosniaAndHerzegowina); - ROW("bs-Latn-BA", Bosnian, LatinScript, BosniaAndHerzegowina); - ROW("ff-Latn-LR", Fulah, LatinScript, Liberia); - ROW("ff-Latn-MR", Fulah, LatinScript, Mauritania); - ROW("pa-Arab-PK", Punjabi, ArabicScript, Pakistan); - ROW("pa-Guru-IN", Punjabi, GurmukhiScript, India); - ROW("shi-Latn-MA", Tachelhit, LatinScript, Morocco); - ROW("shi-Tfng-MA", Tachelhit, TifinaghScript, Morocco); - ROW("sr-Cyrl-BA", Serbian, CyrillicScript, BosniaAndHerzegowina); - ROW("sr-Cyrl-RS", Serbian, CyrillicScript, Serbia); - ROW("sr-Latn-BA", Serbian, LatinScript, BosniaAndHerzegowina); - ROW("sr-Latn-ME", Serbian, LatinScript, Montenegro); - ROW("uz-Arab-AF", Uzbek, ArabicScript, Afghanistan); - ROW("uz-Cyrl-UZ", Uzbek, CyrillicScript, Uzbekistan); - ROW("uz-Latn-UZ", Uzbek, LatinScript, Uzbekistan); - ROW("vai-Latn-LR", Vai, LatinScript, Liberia); - ROW("vai-Vaii-LR", Vai, VaiScript, Liberia); - ROW("yue-Hans-CN", Cantonese, SimplifiedHanScript, China); - ROW("yue-Hant-HK", Cantonese, TraditionalHanScript, HongKong); - ROW("zh-Hans-CN", Chinese, SimplifiedHanScript, China); - ROW("zh-Hans-HK", Chinese, SimplifiedHanScript, HongKong); - ROW("zh-Hans-SG", Chinese, SimplifiedHanScript, Singapore); - ROW("zh-Hant-HK", Chinese, TraditionalHanScript, HongKong); - ROW("zh-Hant-TW", Chinese, TraditionalHanScript, Taiwan); -#undef ROW -} - -void tst_QLocale::fromTags() -{ - QFETCH(const QLocale::Language, language); - QFETCH(const QLocale::Script, script); - QFETCH(const QLocale::Territory, territory); - QBENCHMARK { LOOP(QLocale loc(language, script, territory)) } -} - -void tst_QLocale::fromLangScript_data() -{ - QTest::addColumn("language"); - QTest::addColumn("script"); - -#define ROW(name, lang, text) \ - QTest::newRow(name) << QLocale::lang << QLocale::text - ROW("C", C, AnyScript); - ROW("en-Latn", English, LatinScript); - ROW("sd-Deva", Sindhi, DevanagariScript); - ROW("az-Cyrl", Azerbaijani, CyrillicScript); - ROW("az-Latn", Azerbaijani, LatinScript); - ROW("bs-Cyrl", Bosnian, CyrillicScript); - ROW("bs-Latn", Bosnian, LatinScript); - ROW("ff-Latn", Fulah, LatinScript); - ROW("pa-Arab", Punjabi, ArabicScript); - ROW("pa-Guru", Punjabi, GurmukhiScript); - ROW("shi-Latn", Tachelhit, LatinScript); - ROW("shi-Tfng", Tachelhit, TifinaghScript); - ROW("sr-Cyrl", Serbian, CyrillicScript); - ROW("sr-Latn", Serbian, LatinScript); - ROW("uz-Arab", Uzbek, ArabicScript); - ROW("uz-Cyrl", Uzbek, CyrillicScript); - ROW("uz-Latn", Uzbek, LatinScript); - ROW("vai-Latn", Vai, LatinScript); - ROW("vai-Vaii", Vai, VaiScript); - ROW("yue-Hans", Cantonese, SimplifiedHanScript); - ROW("yue-Hant", Cantonese, TraditionalHanScript); - ROW("zh-Hans", Chinese, SimplifiedHanScript); - ROW("zh-Hant", Chinese, TraditionalHanScript); -#undef ROW -} - -void tst_QLocale::fromLangScript() -{ - QFETCH(const QLocale::Language, language); - QFETCH(const QLocale::Script, script); - QBENCHMARK { LOOP(QLocale loc(language, script, QLocale::AnyTerritory)) } -} - -void tst_QLocale::fromLangLand_data() -{ - QTest::addColumn("language"); - QTest::addColumn("territory"); - -#define ROW(name, lang, land) \ - QTest::newRow(name) << QLocale::lang << QLocale::land - ROW("C", C, AnyTerritory); - ROW("en-DE", English, Germany); - ROW("sd-IN", Sindhi, India); - ROW("az-AZ", Azerbaijani, Azerbaijan); - ROW("bs-BA", Bosnian, BosniaAndHerzegowina); - ROW("ff-LR", Fulah, Liberia); - ROW("ff-MR", Fulah, Mauritania); - ROW("pa-PK", Punjabi, Pakistan); - ROW("pa-IN", Punjabi, India); - ROW("shi-MA", Tachelhit, Morocco); - ROW("sr-BA", Serbian, BosniaAndHerzegowina); - ROW("sr-RS", Serbian, Serbia); - ROW("sr-ME", Serbian, Montenegro); - ROW("uz-AF", Uzbek, Afghanistan); - ROW("uz-UZ", Uzbek, Uzbekistan); - ROW("vai-LR", Vai, Liberia); - ROW("yue-CN", Cantonese, China); - ROW("yue-HK", Cantonese, HongKong); - ROW("zh-CN", Chinese, China); - ROW("zh-HK", Chinese, HongKong); - ROW("zh-SG", Chinese, Singapore); - ROW("zh-TW", Chinese, Taiwan); -#undef ROW -} - -void tst_QLocale::fromLangLand() -{ - QFETCH(const QLocale::Language, language); - QFETCH(const QLocale::Territory, territory); - QBENCHMARK { LOOP(QLocale loc(language, territory)) } -} - -void tst_QLocale::fromScriptLand_data() -{ - QTest::addColumn("script"); - QTest::addColumn("territory"); - -#define ROW(name, text, land) \ - QTest::newRow(name) << QLocale::text << QLocale::land - ROW("Any", AnyScript, AnyTerritory); - ROW("Latn-DE", LatinScript, Germany); - ROW("Deva-IN", DevanagariScript, India); - ROW("Cyrl-AZ", CyrillicScript, Azerbaijan); - ROW("Latn-AZ", LatinScript, Azerbaijan); - ROW("Cyrl-BA", CyrillicScript, BosniaAndHerzegowina); - ROW("Latn-BA", LatinScript, BosniaAndHerzegowina); - ROW("Latn-LR", LatinScript, Liberia); - ROW("Latn-MR", LatinScript, Mauritania); - ROW("Arab-PK", ArabicScript, Pakistan); - ROW("Guru-IN", GurmukhiScript, India); - ROW("Latn-MA", LatinScript, Morocco); - ROW("Tfng-MA", TifinaghScript, Morocco); - ROW("Cyrl-BA", CyrillicScript, BosniaAndHerzegowina); - ROW("Cyrl-RS", CyrillicScript, Serbia); - ROW("Latn-BA", LatinScript, BosniaAndHerzegowina); - ROW("Latn-ME", LatinScript, Montenegro); - ROW("Arab-AF", ArabicScript, Afghanistan); - ROW("Cyrl-UZ", CyrillicScript, Uzbekistan); - ROW("Latn-UZ", LatinScript, Uzbekistan); - ROW("Latn-LR", LatinScript, Liberia); - ROW("Vaii-LR", VaiScript, Liberia); - ROW("Hans-CN", SimplifiedHanScript, China); - ROW("Hant-HK", TraditionalHanScript, HongKong); - ROW("Hans-CN", SimplifiedHanScript, China); - ROW("Hans-HK", SimplifiedHanScript, HongKong); - ROW("Hans-SG", SimplifiedHanScript, Singapore); - ROW("Hant-HK", TraditionalHanScript, HongKong); - ROW("Hant-TW", TraditionalHanScript, Taiwan); -#undef ROW -} - -void tst_QLocale::fromScriptLand() -{ - QFETCH(const QLocale::Script, script); - QFETCH(const QLocale::Territory, territory); - QBENCHMARK { LOOP(QLocale loc(QLocale::AnyLanguage, script, territory)) } -} - -void tst_QLocale::fromLang_data() -{ - QTest::addColumn("language"); - -#define ROW(name, lang) \ - QTest::newRow(name) << QLocale::lang - ROW("C", C); - ROW("en", English); - ROW("sd", Sindhi); - ROW("az", Azerbaijani); - ROW("bs", Bosnian); - ROW("ff", Fulah); - ROW("pa", Punjabi); - ROW("shi", Tachelhit); - ROW("sr", Serbian); - ROW("uz", Uzbek); - ROW("vai", Vai); - ROW("yue", Cantonese); - ROW("zh", Chinese); -#undef ROW -} - -void tst_QLocale::fromLang() -{ - QFETCH(const QLocale::Language, language); - QBENCHMARK { LOOP(QLocale loc(language)) } -} - -void tst_QLocale::fromScript_data() -{ - QTest::addColumn("script"); - -#define ROW(name, text) \ - QTest::newRow(name) << QLocale::text - ROW("Any", AnyScript); - ROW("Latn", LatinScript); - ROW("Deva", DevanagariScript); - ROW("Cyrl", CyrillicScript); - ROW("Arab", ArabicScript); - ROW("Guru", GurmukhiScript); - ROW("Tfng", TifinaghScript); - ROW("Vaii", VaiScript); - ROW("Hans", SimplifiedHanScript); - ROW("Hant", TraditionalHanScript); -#undef ROW -} - -void tst_QLocale::fromScript() -{ - QFETCH(const QLocale::Script, script); - QBENCHMARK { LOOP(QLocale loc(QLocale::AnyLanguage, script, QLocale::AnyTerritory)) } -} - -void tst_QLocale::fromLand_data() -{ - QTest::addColumn("territory"); - -#define ROW(name, land) \ - QTest::newRow(name) << QLocale::land - ROW("Any", AnyTerritory); - ROW("DE", Germany); - ROW("IN", India); - ROW("AZ", Azerbaijan); - ROW("BA", BosniaAndHerzegowina); - ROW("LR", Liberia); - ROW("MR", Mauritania); - ROW("PK", Pakistan); - ROW("MA", Morocco); - ROW("RS", Serbia); - ROW("ME", Montenegro); - ROW("AF", Afghanistan); - ROW("UZ", Uzbekistan); - ROW("CN", China); - ROW("HK", HongKong); - ROW("SG", Singapore); - ROW("TW", Taiwan); -#undef ROW -} - -void tst_QLocale::fromLand() -{ - QFETCH(const QLocale::Territory, territory); - QBENCHMARK { LOOP(QLocale loc(QLocale::AnyLanguage, territory)) } -} - -void tst_QLocale::toUpper_QLocale_1() -{ - QString s = data(); - QBENCHMARK { LOOP(QString t(QLocale().toUpper(s))) } -} - -void tst_QLocale::toUpper_QLocale_2() -{ - QString s = data(); - QLocale l; - QBENCHMARK { LOOP(QString t(l.toUpper(s))) } -} - -void tst_QLocale::toUpper_QString() -{ - QString s = data(); - QBENCHMARK { LOOP(QString t(s.toUpper())) } -} - -void tst_QLocale::number_QString() -{ - QString s; - QBENCHMARK { - s = QString::number(12345678); - } -} - -QTEST_MAIN(tst_QLocale) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/text/qlocale/tst_bench_qlocale.cpp b/tests/benchmarks/corelib/text/qlocale/tst_bench_qlocale.cpp new file mode 100644 index 0000000000..23a64526eb --- /dev/null +++ b/tests/benchmarks/corelib/text/qlocale/tst_bench_qlocale.cpp @@ -0,0 +1,397 @@ +/**************************************************************************** +** +** Copyright (C) 2020 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module 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_QLocale : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void fromString_data(); + void fromString(); + void fromTags_data(); + void fromTags(); + void fromLangScript_data(); + void fromLangScript(); + void fromLangLand_data(); + void fromLangLand(); + void fromScriptLand_data(); + void fromScriptLand(); + void fromLang_data(); + void fromLang(); + void fromScript_data(); + void fromScript(); + void fromLand_data(); + void fromLand(); + void toUpper_QLocale_1(); + void toUpper_QLocale_2(); + void toUpper_QString(); + void number_QString(); +}; + +static QString data() +{ + return QStringLiteral("/qt-5/qtbase/tests/benchmarks/corelib/tools/qlocale"); +} + +// Make individual cycles O(a few) msecs, rather than tiny fractions thereof: +#define LOOP(s) for (int i = 0; i < 5000; ++i) { s; } + +void tst_QLocale::fromString_data() +{ + QTest::addColumn("name"); + + QTest::newRow("C") << QStringLiteral("C"); +#define ROW(name) QTest::newRow(name) << QStringLiteral(name) + ROW("en-Latn-DE"); + ROW("sd-Deva-IN"); + ROW("az-Cyrl-AZ"); + ROW("az-Latn-AZ"); + ROW("bs-Cyrl-BA"); + ROW("bs-Latn-BA"); + ROW("ff-Latn-LR"); + ROW("ff-Latn-MR"); + ROW("pa-Arab-PK"); + ROW("pa-Guru-IN"); + ROW("shi-Latn-MA"); + ROW("shi-Tfng-MA"); + ROW("sr-Cyrl-BA"); + ROW("sr-Cyrl-RS"); + ROW("sr-Latn-BA"); + ROW("sr-Latn-ME"); + ROW("uz-Arab-AF"); + ROW("uz-Cyrl-UZ"); + ROW("uz-Latn-UZ"); + ROW("vai-Latn-LR"); + ROW("vai-Vaii-LR"); + ROW("yue-Hans-CN"); + ROW("yue-Hant-HK"); + ROW("zh-Hans-CN"); + ROW("zh-Hans-HK"); + ROW("zh-Hans-SG"); + ROW("zh-Hant-HK"); + ROW("zh-Hant-TW"); +#undef ROW +} + +void tst_QLocale::fromString() +{ + QFETCH(const QString, name); + QBENCHMARK { LOOP(QLocale loc(name)) } +} + +void tst_QLocale::fromTags_data() +{ + QTest::addColumn("language"); + QTest::addColumn("script"); + QTest::addColumn("territory"); + +#define ROW(name, lang, text, land) \ + QTest::newRow(name) << QLocale::lang << QLocale::text << QLocale::land + ROW("C", C, AnyScript, AnyTerritory); + ROW("en-Latn-DE", English, LatinScript, Germany); + ROW("sd-Deva-IN", Sindhi, DevanagariScript, India); + ROW("az-Cyrl-AZ", Azerbaijani, CyrillicScript, Azerbaijan); + ROW("az-Latn-AZ", Azerbaijani, LatinScript, Azerbaijan); + ROW("bs-Cyrl-BA", Bosnian, CyrillicScript, BosniaAndHerzegowina); + ROW("bs-Latn-BA", Bosnian, LatinScript, BosniaAndHerzegowina); + ROW("ff-Latn-LR", Fulah, LatinScript, Liberia); + ROW("ff-Latn-MR", Fulah, LatinScript, Mauritania); + ROW("pa-Arab-PK", Punjabi, ArabicScript, Pakistan); + ROW("pa-Guru-IN", Punjabi, GurmukhiScript, India); + ROW("shi-Latn-MA", Tachelhit, LatinScript, Morocco); + ROW("shi-Tfng-MA", Tachelhit, TifinaghScript, Morocco); + ROW("sr-Cyrl-BA", Serbian, CyrillicScript, BosniaAndHerzegowina); + ROW("sr-Cyrl-RS", Serbian, CyrillicScript, Serbia); + ROW("sr-Latn-BA", Serbian, LatinScript, BosniaAndHerzegowina); + ROW("sr-Latn-ME", Serbian, LatinScript, Montenegro); + ROW("uz-Arab-AF", Uzbek, ArabicScript, Afghanistan); + ROW("uz-Cyrl-UZ", Uzbek, CyrillicScript, Uzbekistan); + ROW("uz-Latn-UZ", Uzbek, LatinScript, Uzbekistan); + ROW("vai-Latn-LR", Vai, LatinScript, Liberia); + ROW("vai-Vaii-LR", Vai, VaiScript, Liberia); + ROW("yue-Hans-CN", Cantonese, SimplifiedHanScript, China); + ROW("yue-Hant-HK", Cantonese, TraditionalHanScript, HongKong); + ROW("zh-Hans-CN", Chinese, SimplifiedHanScript, China); + ROW("zh-Hans-HK", Chinese, SimplifiedHanScript, HongKong); + ROW("zh-Hans-SG", Chinese, SimplifiedHanScript, Singapore); + ROW("zh-Hant-HK", Chinese, TraditionalHanScript, HongKong); + ROW("zh-Hant-TW", Chinese, TraditionalHanScript, Taiwan); +#undef ROW +} + +void tst_QLocale::fromTags() +{ + QFETCH(const QLocale::Language, language); + QFETCH(const QLocale::Script, script); + QFETCH(const QLocale::Territory, territory); + QBENCHMARK { LOOP(QLocale loc(language, script, territory)) } +} + +void tst_QLocale::fromLangScript_data() +{ + QTest::addColumn("language"); + QTest::addColumn("script"); + +#define ROW(name, lang, text) \ + QTest::newRow(name) << QLocale::lang << QLocale::text + ROW("C", C, AnyScript); + ROW("en-Latn", English, LatinScript); + ROW("sd-Deva", Sindhi, DevanagariScript); + ROW("az-Cyrl", Azerbaijani, CyrillicScript); + ROW("az-Latn", Azerbaijani, LatinScript); + ROW("bs-Cyrl", Bosnian, CyrillicScript); + ROW("bs-Latn", Bosnian, LatinScript); + ROW("ff-Latn", Fulah, LatinScript); + ROW("pa-Arab", Punjabi, ArabicScript); + ROW("pa-Guru", Punjabi, GurmukhiScript); + ROW("shi-Latn", Tachelhit, LatinScript); + ROW("shi-Tfng", Tachelhit, TifinaghScript); + ROW("sr-Cyrl", Serbian, CyrillicScript); + ROW("sr-Latn", Serbian, LatinScript); + ROW("uz-Arab", Uzbek, ArabicScript); + ROW("uz-Cyrl", Uzbek, CyrillicScript); + ROW("uz-Latn", Uzbek, LatinScript); + ROW("vai-Latn", Vai, LatinScript); + ROW("vai-Vaii", Vai, VaiScript); + ROW("yue-Hans", Cantonese, SimplifiedHanScript); + ROW("yue-Hant", Cantonese, TraditionalHanScript); + ROW("zh-Hans", Chinese, SimplifiedHanScript); + ROW("zh-Hant", Chinese, TraditionalHanScript); +#undef ROW +} + +void tst_QLocale::fromLangScript() +{ + QFETCH(const QLocale::Language, language); + QFETCH(const QLocale::Script, script); + QBENCHMARK { LOOP(QLocale loc(language, script, QLocale::AnyTerritory)) } +} + +void tst_QLocale::fromLangLand_data() +{ + QTest::addColumn("language"); + QTest::addColumn("territory"); + +#define ROW(name, lang, land) \ + QTest::newRow(name) << QLocale::lang << QLocale::land + ROW("C", C, AnyTerritory); + ROW("en-DE", English, Germany); + ROW("sd-IN", Sindhi, India); + ROW("az-AZ", Azerbaijani, Azerbaijan); + ROW("bs-BA", Bosnian, BosniaAndHerzegowina); + ROW("ff-LR", Fulah, Liberia); + ROW("ff-MR", Fulah, Mauritania); + ROW("pa-PK", Punjabi, Pakistan); + ROW("pa-IN", Punjabi, India); + ROW("shi-MA", Tachelhit, Morocco); + ROW("sr-BA", Serbian, BosniaAndHerzegowina); + ROW("sr-RS", Serbian, Serbia); + ROW("sr-ME", Serbian, Montenegro); + ROW("uz-AF", Uzbek, Afghanistan); + ROW("uz-UZ", Uzbek, Uzbekistan); + ROW("vai-LR", Vai, Liberia); + ROW("yue-CN", Cantonese, China); + ROW("yue-HK", Cantonese, HongKong); + ROW("zh-CN", Chinese, China); + ROW("zh-HK", Chinese, HongKong); + ROW("zh-SG", Chinese, Singapore); + ROW("zh-TW", Chinese, Taiwan); +#undef ROW +} + +void tst_QLocale::fromLangLand() +{ + QFETCH(const QLocale::Language, language); + QFETCH(const QLocale::Territory, territory); + QBENCHMARK { LOOP(QLocale loc(language, territory)) } +} + +void tst_QLocale::fromScriptLand_data() +{ + QTest::addColumn("script"); + QTest::addColumn("territory"); + +#define ROW(name, text, land) \ + QTest::newRow(name) << QLocale::text << QLocale::land + ROW("Any", AnyScript, AnyTerritory); + ROW("Latn-DE", LatinScript, Germany); + ROW("Deva-IN", DevanagariScript, India); + ROW("Cyrl-AZ", CyrillicScript, Azerbaijan); + ROW("Latn-AZ", LatinScript, Azerbaijan); + ROW("Cyrl-BA", CyrillicScript, BosniaAndHerzegowina); + ROW("Latn-BA", LatinScript, BosniaAndHerzegowina); + ROW("Latn-LR", LatinScript, Liberia); + ROW("Latn-MR", LatinScript, Mauritania); + ROW("Arab-PK", ArabicScript, Pakistan); + ROW("Guru-IN", GurmukhiScript, India); + ROW("Latn-MA", LatinScript, Morocco); + ROW("Tfng-MA", TifinaghScript, Morocco); + ROW("Cyrl-BA", CyrillicScript, BosniaAndHerzegowina); + ROW("Cyrl-RS", CyrillicScript, Serbia); + ROW("Latn-BA", LatinScript, BosniaAndHerzegowina); + ROW("Latn-ME", LatinScript, Montenegro); + ROW("Arab-AF", ArabicScript, Afghanistan); + ROW("Cyrl-UZ", CyrillicScript, Uzbekistan); + ROW("Latn-UZ", LatinScript, Uzbekistan); + ROW("Latn-LR", LatinScript, Liberia); + ROW("Vaii-LR", VaiScript, Liberia); + ROW("Hans-CN", SimplifiedHanScript, China); + ROW("Hant-HK", TraditionalHanScript, HongKong); + ROW("Hans-CN", SimplifiedHanScript, China); + ROW("Hans-HK", SimplifiedHanScript, HongKong); + ROW("Hans-SG", SimplifiedHanScript, Singapore); + ROW("Hant-HK", TraditionalHanScript, HongKong); + ROW("Hant-TW", TraditionalHanScript, Taiwan); +#undef ROW +} + +void tst_QLocale::fromScriptLand() +{ + QFETCH(const QLocale::Script, script); + QFETCH(const QLocale::Territory, territory); + QBENCHMARK { LOOP(QLocale loc(QLocale::AnyLanguage, script, territory)) } +} + +void tst_QLocale::fromLang_data() +{ + QTest::addColumn("language"); + +#define ROW(name, lang) \ + QTest::newRow(name) << QLocale::lang + ROW("C", C); + ROW("en", English); + ROW("sd", Sindhi); + ROW("az", Azerbaijani); + ROW("bs", Bosnian); + ROW("ff", Fulah); + ROW("pa", Punjabi); + ROW("shi", Tachelhit); + ROW("sr", Serbian); + ROW("uz", Uzbek); + ROW("vai", Vai); + ROW("yue", Cantonese); + ROW("zh", Chinese); +#undef ROW +} + +void tst_QLocale::fromLang() +{ + QFETCH(const QLocale::Language, language); + QBENCHMARK { LOOP(QLocale loc(language)) } +} + +void tst_QLocale::fromScript_data() +{ + QTest::addColumn("script"); + +#define ROW(name, text) \ + QTest::newRow(name) << QLocale::text + ROW("Any", AnyScript); + ROW("Latn", LatinScript); + ROW("Deva", DevanagariScript); + ROW("Cyrl", CyrillicScript); + ROW("Arab", ArabicScript); + ROW("Guru", GurmukhiScript); + ROW("Tfng", TifinaghScript); + ROW("Vaii", VaiScript); + ROW("Hans", SimplifiedHanScript); + ROW("Hant", TraditionalHanScript); +#undef ROW +} + +void tst_QLocale::fromScript() +{ + QFETCH(const QLocale::Script, script); + QBENCHMARK { LOOP(QLocale loc(QLocale::AnyLanguage, script, QLocale::AnyTerritory)) } +} + +void tst_QLocale::fromLand_data() +{ + QTest::addColumn("territory"); + +#define ROW(name, land) \ + QTest::newRow(name) << QLocale::land + ROW("Any", AnyTerritory); + ROW("DE", Germany); + ROW("IN", India); + ROW("AZ", Azerbaijan); + ROW("BA", BosniaAndHerzegowina); + ROW("LR", Liberia); + ROW("MR", Mauritania); + ROW("PK", Pakistan); + ROW("MA", Morocco); + ROW("RS", Serbia); + ROW("ME", Montenegro); + ROW("AF", Afghanistan); + ROW("UZ", Uzbekistan); + ROW("CN", China); + ROW("HK", HongKong); + ROW("SG", Singapore); + ROW("TW", Taiwan); +#undef ROW +} + +void tst_QLocale::fromLand() +{ + QFETCH(const QLocale::Territory, territory); + QBENCHMARK { LOOP(QLocale loc(QLocale::AnyLanguage, territory)) } +} + +void tst_QLocale::toUpper_QLocale_1() +{ + QString s = data(); + QBENCHMARK { LOOP(QString t(QLocale().toUpper(s))) } +} + +void tst_QLocale::toUpper_QLocale_2() +{ + QString s = data(); + QLocale l; + QBENCHMARK { LOOP(QString t(l.toUpper(s))) } +} + +void tst_QLocale::toUpper_QString() +{ + QString s = data(); + QBENCHMARK { LOOP(QString t(s.toUpper())) } +} + +void tst_QLocale::number_QString() +{ + QString s; + QBENCHMARK { + s = QString::number(12345678); + } +} + +QTEST_MAIN(tst_QLocale) + +#include "tst_bench_qlocale.moc" diff --git a/tests/benchmarks/corelib/text/qstringbuilder/CMakeLists.txt b/tests/benchmarks/corelib/text/qstringbuilder/CMakeLists.txt index 33b1b5fe5e..b450aa50a0 100644 --- a/tests/benchmarks/corelib/text/qstringbuilder/CMakeLists.txt +++ b/tests/benchmarks/corelib/text/qstringbuilder/CMakeLists.txt @@ -1,18 +1,12 @@ -# Generated from qstringbuilder.pro. - ##################################################################### ## tst_bench_qstringbuilder Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qstringbuilder SOURCES - main.cpp + tst_bench_qstringbuilder.cpp PUBLIC_LIBRARIES Qt::Test COMPILE_OPTIONS -g ) - -#### Keys ignored in scope 1:.:.:qstringbuilder.pro:: -# QMAKE_CFLAGS = "-g" -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/text/qstringbuilder/main.cpp b/tests/benchmarks/corelib/text/qstringbuilder/main.cpp deleted file mode 100644 index 757e2cc683..0000000000 --- a/tests/benchmarks/corelib/text/qstringbuilder/main.cpp +++ /dev/null @@ -1,415 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite module 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$ -** -****************************************************************************/ - -// Select one of the scenarios below -#define SCENARIO 1 - -#if SCENARIO == 1 -// this is the "no harm done" version. Only operator% is active, -// with NO_CAST * defined -#undef QT_USE_FAST_OPERATOR_PLUS -#undef QT_USE_FAST_CONCATENATION -#define QT_NO_CAST_FROM_ASCII -#define QT_NO_CAST_TO_ASCII -#endif - - -#if SCENARIO == 2 -// this is the "full" version. Operator+ is replaced by a QStringBuilder -// based version -// with NO_CAST * defined -#define QT_USE_FAST_OPERATOR_PLUS -#define QT_USE_FAST_CONCATENATION -#define QT_NO_CAST_FROM_ASCII -#define QT_NO_CAST_TO_ASCII -#endif - -#if SCENARIO == 3 -// this is the "no harm done" version. Only operator% is active, -// with NO_CAST * _not_ defined -#undef QT_USE_FAST_OPERATOR_PLUS -#undef QT_USE_FAST_CONCATENATION -#undef QT_NO_CAST_FROM_ASCII -#undef QT_NO_CAST_TO_ASCII -#endif - -#if SCENARIO == 4 -// this is the "full" version. Operator+ is replaced by a QStringBuilder -// based version -// with NO_CAST * _not_ defined -#define QT_USE_FAST_OPERATOR_PLUS -#define QT_USE_FAST_CONCATENATION -#undef QT_NO_CAST_FROM_ASCII -#undef QT_NO_CAST_TO_ASCII -#endif - - -#include -#include -#include -#include - -#include - -#include - -// Select one of the scenarios below -#if SCENARIO == 1 -#define P % -#elif SCENARIO == 2 -#define P + -#elif SCENARIO == 3 -#define P % -#elif SCENARIO == 4 -#define P + -#endif - -#define COMPARE(a, b) QCOMPARE(a, b) -//#define COMPARE(a, b) - -#define SEP(s) qDebug() << "\n\n-------- " s " ---------"; - -#define LITERAL "some string literal" - -class tst_qstringbuilder : public QObject -{ - Q_OBJECT - -public: - tst_qstringbuilder() - : l1literal(LITERAL), - l1string(LITERAL), - ba(LITERAL), - string(l1string), - stdstring(LITERAL), - achar('c'), - r2(QLatin1String(LITERAL LITERAL)), - r3(QLatin1String(LITERAL LITERAL LITERAL)), - r4(QLatin1String(LITERAL LITERAL LITERAL LITERAL)), - r5(QLatin1String(LITERAL LITERAL LITERAL LITERAL LITERAL)) - {} - - -public: - enum { N = 10000 }; - - int run_traditional() - { - int s = 0; - for (int i = 0; i < N; ++i) { -#if 0 - s += QString(l1string + l1string).size(); - s += QString(l1string + l1string + l1string).size(); - s += QString(l1string + l1string + l1string + l1string).size(); - s += QString(l1string + l1string + l1string + l1string + l1string).size(); -#endif - s += QString(achar + l1string + achar).size(); - } - return s; - } - - int run_builder() - { - int s = 0; - for (int i = 0; i < N; ++i) { -#if 0 - s += QString(l1literal P l1literal).size(); - s += QString(l1literal P l1literal P l1literal).size(); - s += QString(l1literal P l1literal P l1literal P l1literal).size(); - s += QString(l1literal P l1literal P l1literal P l1literal P l1literal).size(); -#endif - s += QString(achar % l1literal % achar).size(); - } - return s; - } - -private slots: - - void separator_0() { - qDebug() << "\nIn each block the QStringBuilder based result appear first " - "(with a 'b_' prefix), QStringBased second ('q_' prefix), std::string " - "last ('s_' prefix)\n"; - } - - void separator_1() { SEP("literal + literal (builder first)"); } - - void b_2_l1literal() { - QBENCHMARK { r = l1literal P l1literal; } - COMPARE(r, r2); - } - #ifndef QT_NO_CAST_FROM_ASCII - void b_l1literal_LITERAL() { - QBENCHMARK { r = l1literal P LITERAL; } - COMPARE(r, r2); - } - #endif - void q_2_l1string() { - QBENCHMARK { r = l1string + l1string; } - COMPARE(r, r2); - } - - - void separator_2() { SEP("2 strings"); } - - void b_2_string() { - QBENCHMARK { r = string P string; } - COMPARE(r, r2); - } - void q_2_string() { - QBENCHMARK { r = string + string; } - COMPARE(r, r2); - } - void s_2_string() { - QBENCHMARK { stdr = stdstring + stdstring; } - COMPARE(stdr, stdstring + stdstring); - } - - - void separator_2b() { SEP("3 strings"); } - - void b_3_string() { - QBENCHMARK { r = string P string P string; } - COMPARE(r, r3); - } - void q_3_string() { - QBENCHMARK { r = string + string + string; } - COMPARE(r, r3); - } - void s_3_string() { - QBENCHMARK { stdr = stdstring + stdstring + stdstring; } - COMPARE(stdr, stdstring + stdstring + stdstring); - } - - void separator_2e() { SEP("4 strings"); } - - void b_4_string() { - QBENCHMARK { r = string P string P string P string; } - COMPARE(r, r4); - } - void q_4_string() { - QBENCHMARK { r = string + string + string + string; } - COMPARE(r, r4); - } - void s_4_string() { - QBENCHMARK { stdr = stdstring + stdstring + stdstring + stdstring; } - COMPARE(stdr, stdstring + stdstring + stdstring + stdstring); - } - - - - void separator_2a() { SEP("string + literal (builder first)"); } - - void b_string_l1literal() { - QBENCHMARK { r = string % l1literal; } - COMPARE(r, r2); - } - #ifndef QT_NO_CAST_FROM_ASCII - void b_string_LITERAL() { - QBENCHMARK { r = string P LITERAL; } - COMPARE(r, r2); - } - void b_LITERAL_string() { - QBENCHMARK { r = LITERAL P string; } - COMPARE(r, r2); - } - #endif - void b_string_l1string() { - QBENCHMARK { r = string P l1string; } - COMPARE(r, r2); - } - void q_string_l1literal() { - QBENCHMARK { r = string + l1string; } - COMPARE(r, r2); - } - void q_string_l1string() { - QBENCHMARK { r = string + l1string; } - COMPARE(r, r2); - } - void s_LITERAL_string() { - QBENCHMARK { stdr = LITERAL + stdstring; } - COMPARE(stdr, stdstring + stdstring); - } - - - void separator_3() { SEP("3 literals"); } - - void b_3_l1literal() { - QBENCHMARK { r = l1literal P l1literal P l1literal; } - COMPARE(r, r3); - } - void q_3_l1string() { - QBENCHMARK { r = l1string + l1string + l1string; } - COMPARE(r, r3); - } - void s_3_l1string() { - QBENCHMARK { stdr = stdstring + LITERAL + LITERAL; } - COMPARE(stdr, stdstring + stdstring + stdstring); - } - - - void separator_4() { SEP("4 literals"); } - - void b_4_l1literal() { - QBENCHMARK { r = l1literal P l1literal P l1literal P l1literal; } - COMPARE(r, r4); - } - void q_4_l1string() { - QBENCHMARK { r = l1string + l1string + l1string + l1string; } - COMPARE(r, r4); - } - - - void separator_5() { SEP("5 literals"); } - - void b_5_l1literal() { - QBENCHMARK { r = l1literal P l1literal P l1literal P l1literal P l1literal; } - COMPARE(r, r5); - } - - void q_5_l1string() { - QBENCHMARK { r = l1string + l1string + l1string + l1string + l1string; } - COMPARE(r, r5); - } - - - void separator_6() { SEP("4 chars"); } - - void b_string_4_char() { - QBENCHMARK { r = string + achar + achar + achar + achar; } - COMPARE(r, QString(string P achar P achar P achar P achar)); - } - - void q_string_4_char() { - QBENCHMARK { r = string + achar + achar + achar + achar; } - COMPARE(r, QString(string P achar P achar P achar P achar)); - } - - void s_string_4_char() { - QBENCHMARK { stdr = stdstring + 'c' + 'c' + 'c' + 'c'; } - COMPARE(stdr, stdstring + 'c' + 'c' + 'c' + 'c'); - } - - - void separator_7() { SEP("char + string + char"); } - - void b_char_string_char() { - QBENCHMARK { r = achar + string + achar; } - COMPARE(r, QString(achar P string P achar)); - } - - void q_char_string_char() { - QBENCHMARK { r = achar + string + achar; } - COMPARE(r, QString(achar P string P achar)); - } - - void s_char_string_char() { - QBENCHMARK { stdr = 'c' + stdstring + 'c'; } - COMPARE(stdr, 'c' + stdstring + 'c'); - } - - - void separator_8() { SEP("string.arg"); } - - void b_string_arg() { - const QString pattern = l1string + QString::fromLatin1("%1") + l1string; - QBENCHMARK { r = l1literal P string P l1literal; } - COMPARE(r, r3); - } - - void q_string_arg() { - const QString pattern = l1string + QLatin1String("%1") + l1string; - QBENCHMARK { r = pattern.arg(string); } - COMPARE(r, r3); - } - - void q_bytearray_arg() { - QByteArray result; - QBENCHMARK { result = ba + ba + ba; } - } - - - void separator_9() { SEP("QString::reserve()"); } - - void b_reserve() { - QBENCHMARK { - r.clear(); - r = string P string P string P string; - } - COMPARE(r, r4); - } - void b_reserve_lit() { - QBENCHMARK { - r.clear(); - r = string P l1literal P string P string; - } - COMPARE(r, r4); - } - void s_reserve() { - QBENCHMARK { - r.clear(); - r.reserve(string.size() + string.size() + string.size() + string.size()); - r += string; - r += string; - r += string; - r += string; - } - COMPARE(r, r4); - } - void s_reserve_lit() { - QBENCHMARK { - r.clear(); - //r.reserve(string.size() + qstrlen(l1string.latin1()) - // + string.size() + string.size()); - r.reserve(1024); - r += string; - r += l1string; - r += string; - r += string; - } - COMPARE(r, r4); - } - -private: - const QLatin1String l1literal; - const QLatin1String l1string; - const QByteArray ba; - const QString string; - const std::string stdstring; - const QLatin1Char achar; - const QString r2, r3, r4, r5; - - // short cuts for results - QString r; - std::string stdr; -}; - -QTEST_MAIN(tst_qstringbuilder) - -#undef P - -#include "main.moc" diff --git a/tests/benchmarks/corelib/text/qstringbuilder/tst_bench_qstringbuilder.cpp b/tests/benchmarks/corelib/text/qstringbuilder/tst_bench_qstringbuilder.cpp new file mode 100644 index 0000000000..acb7c14169 --- /dev/null +++ b/tests/benchmarks/corelib/text/qstringbuilder/tst_bench_qstringbuilder.cpp @@ -0,0 +1,415 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the test suite module 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$ +** +****************************************************************************/ + +// Select one of the scenarios below +#define SCENARIO 1 + +#if SCENARIO == 1 +// this is the "no harm done" version. Only operator% is active, +// with NO_CAST * defined +#undef QT_USE_FAST_OPERATOR_PLUS +#undef QT_USE_FAST_CONCATENATION +#define QT_NO_CAST_FROM_ASCII +#define QT_NO_CAST_TO_ASCII +#endif + + +#if SCENARIO == 2 +// this is the "full" version. Operator+ is replaced by a QStringBuilder +// based version +// with NO_CAST * defined +#define QT_USE_FAST_OPERATOR_PLUS +#define QT_USE_FAST_CONCATENATION +#define QT_NO_CAST_FROM_ASCII +#define QT_NO_CAST_TO_ASCII +#endif + +#if SCENARIO == 3 +// this is the "no harm done" version. Only operator% is active, +// with NO_CAST * _not_ defined +#undef QT_USE_FAST_OPERATOR_PLUS +#undef QT_USE_FAST_CONCATENATION +#undef QT_NO_CAST_FROM_ASCII +#undef QT_NO_CAST_TO_ASCII +#endif + +#if SCENARIO == 4 +// this is the "full" version. Operator+ is replaced by a QStringBuilder +// based version +// with NO_CAST * _not_ defined +#define QT_USE_FAST_OPERATOR_PLUS +#define QT_USE_FAST_CONCATENATION +#undef QT_NO_CAST_FROM_ASCII +#undef QT_NO_CAST_TO_ASCII +#endif + + +#include +#include +#include +#include + +#include + +#include + +// Select one of the scenarios below +#if SCENARIO == 1 +#define P % +#elif SCENARIO == 2 +#define P + +#elif SCENARIO == 3 +#define P % +#elif SCENARIO == 4 +#define P + +#endif + +#define COMPARE(a, b) QCOMPARE(a, b) +//#define COMPARE(a, b) + +#define SEP(s) qDebug() << "\n\n-------- " s " ---------"; + +#define LITERAL "some string literal" + +class tst_QStringBuilder : public QObject +{ + Q_OBJECT + +public: + tst_QStringBuilder() + : l1literal(LITERAL), + l1string(LITERAL), + ba(LITERAL), + string(l1string), + stdstring(LITERAL), + achar('c'), + r2(QLatin1String(LITERAL LITERAL)), + r3(QLatin1String(LITERAL LITERAL LITERAL)), + r4(QLatin1String(LITERAL LITERAL LITERAL LITERAL)), + r5(QLatin1String(LITERAL LITERAL LITERAL LITERAL LITERAL)) + {} + + +public: + enum { N = 10000 }; + + int run_traditional() + { + int s = 0; + for (int i = 0; i < N; ++i) { +#if 0 + s += QString(l1string + l1string).size(); + s += QString(l1string + l1string + l1string).size(); + s += QString(l1string + l1string + l1string + l1string).size(); + s += QString(l1string + l1string + l1string + l1string + l1string).size(); +#endif + s += QString(achar + l1string + achar).size(); + } + return s; + } + + int run_builder() + { + int s = 0; + for (int i = 0; i < N; ++i) { +#if 0 + s += QString(l1literal P l1literal).size(); + s += QString(l1literal P l1literal P l1literal).size(); + s += QString(l1literal P l1literal P l1literal P l1literal).size(); + s += QString(l1literal P l1literal P l1literal P l1literal P l1literal).size(); +#endif + s += QString(achar % l1literal % achar).size(); + } + return s; + } + +private slots: + + void separator_0() { + qDebug() << "\nIn each block the QStringBuilder based result appear first " + "(with a 'b_' prefix), QStringBased second ('q_' prefix), std::string " + "last ('s_' prefix)\n"; + } + + void separator_1() { SEP("literal + literal (builder first)"); } + + void b_2_l1literal() { + QBENCHMARK { r = l1literal P l1literal; } + COMPARE(r, r2); + } + #ifndef QT_NO_CAST_FROM_ASCII + void b_l1literal_LITERAL() { + QBENCHMARK { r = l1literal P LITERAL; } + COMPARE(r, r2); + } + #endif + void q_2_l1string() { + QBENCHMARK { r = l1string + l1string; } + COMPARE(r, r2); + } + + + void separator_2() { SEP("2 strings"); } + + void b_2_string() { + QBENCHMARK { r = string P string; } + COMPARE(r, r2); + } + void q_2_string() { + QBENCHMARK { r = string + string; } + COMPARE(r, r2); + } + void s_2_string() { + QBENCHMARK { stdr = stdstring + stdstring; } + COMPARE(stdr, stdstring + stdstring); + } + + + void separator_2b() { SEP("3 strings"); } + + void b_3_string() { + QBENCHMARK { r = string P string P string; } + COMPARE(r, r3); + } + void q_3_string() { + QBENCHMARK { r = string + string + string; } + COMPARE(r, r3); + } + void s_3_string() { + QBENCHMARK { stdr = stdstring + stdstring + stdstring; } + COMPARE(stdr, stdstring + stdstring + stdstring); + } + + void separator_2e() { SEP("4 strings"); } + + void b_4_string() { + QBENCHMARK { r = string P string P string P string; } + COMPARE(r, r4); + } + void q_4_string() { + QBENCHMARK { r = string + string + string + string; } + COMPARE(r, r4); + } + void s_4_string() { + QBENCHMARK { stdr = stdstring + stdstring + stdstring + stdstring; } + COMPARE(stdr, stdstring + stdstring + stdstring + stdstring); + } + + + + void separator_2a() { SEP("string + literal (builder first)"); } + + void b_string_l1literal() { + QBENCHMARK { r = string % l1literal; } + COMPARE(r, r2); + } + #ifndef QT_NO_CAST_FROM_ASCII + void b_string_LITERAL() { + QBENCHMARK { r = string P LITERAL; } + COMPARE(r, r2); + } + void b_LITERAL_string() { + QBENCHMARK { r = LITERAL P string; } + COMPARE(r, r2); + } + #endif + void b_string_l1string() { + QBENCHMARK { r = string P l1string; } + COMPARE(r, r2); + } + void q_string_l1literal() { + QBENCHMARK { r = string + l1string; } + COMPARE(r, r2); + } + void q_string_l1string() { + QBENCHMARK { r = string + l1string; } + COMPARE(r, r2); + } + void s_LITERAL_string() { + QBENCHMARK { stdr = LITERAL + stdstring; } + COMPARE(stdr, stdstring + stdstring); + } + + + void separator_3() { SEP("3 literals"); } + + void b_3_l1literal() { + QBENCHMARK { r = l1literal P l1literal P l1literal; } + COMPARE(r, r3); + } + void q_3_l1string() { + QBENCHMARK { r = l1string + l1string + l1string; } + COMPARE(r, r3); + } + void s_3_l1string() { + QBENCHMARK { stdr = stdstring + LITERAL + LITERAL; } + COMPARE(stdr, stdstring + stdstring + stdstring); + } + + + void separator_4() { SEP("4 literals"); } + + void b_4_l1literal() { + QBENCHMARK { r = l1literal P l1literal P l1literal P l1literal; } + COMPARE(r, r4); + } + void q_4_l1string() { + QBENCHMARK { r = l1string + l1string + l1string + l1string; } + COMPARE(r, r4); + } + + + void separator_5() { SEP("5 literals"); } + + void b_5_l1literal() { + QBENCHMARK { r = l1literal P l1literal P l1literal P l1literal P l1literal; } + COMPARE(r, r5); + } + + void q_5_l1string() { + QBENCHMARK { r = l1string + l1string + l1string + l1string + l1string; } + COMPARE(r, r5); + } + + + void separator_6() { SEP("4 chars"); } + + void b_string_4_char() { + QBENCHMARK { r = string + achar + achar + achar + achar; } + COMPARE(r, QString(string P achar P achar P achar P achar)); + } + + void q_string_4_char() { + QBENCHMARK { r = string + achar + achar + achar + achar; } + COMPARE(r, QString(string P achar P achar P achar P achar)); + } + + void s_string_4_char() { + QBENCHMARK { stdr = stdstring + 'c' + 'c' + 'c' + 'c'; } + COMPARE(stdr, stdstring + 'c' + 'c' + 'c' + 'c'); + } + + + void separator_7() { SEP("char + string + char"); } + + void b_char_string_char() { + QBENCHMARK { r = achar + string + achar; } + COMPARE(r, QString(achar P string P achar)); + } + + void q_char_string_char() { + QBENCHMARK { r = achar + string + achar; } + COMPARE(r, QString(achar P string P achar)); + } + + void s_char_string_char() { + QBENCHMARK { stdr = 'c' + stdstring + 'c'; } + COMPARE(stdr, 'c' + stdstring + 'c'); + } + + + void separator_8() { SEP("string.arg"); } + + void b_string_arg() { + const QString pattern = l1string + QString::fromLatin1("%1") + l1string; + QBENCHMARK { r = l1literal P string P l1literal; } + COMPARE(r, r3); + } + + void q_string_arg() { + const QString pattern = l1string + QLatin1String("%1") + l1string; + QBENCHMARK { r = pattern.arg(string); } + COMPARE(r, r3); + } + + void q_bytearray_arg() { + QByteArray result; + QBENCHMARK { result = ba + ba + ba; } + } + + + void separator_9() { SEP("QString::reserve()"); } + + void b_reserve() { + QBENCHMARK { + r.clear(); + r = string P string P string P string; + } + COMPARE(r, r4); + } + void b_reserve_lit() { + QBENCHMARK { + r.clear(); + r = string P l1literal P string P string; + } + COMPARE(r, r4); + } + void s_reserve() { + QBENCHMARK { + r.clear(); + r.reserve(string.size() + string.size() + string.size() + string.size()); + r += string; + r += string; + r += string; + r += string; + } + COMPARE(r, r4); + } + void s_reserve_lit() { + QBENCHMARK { + r.clear(); + //r.reserve(string.size() + qstrlen(l1string.latin1()) + // + string.size() + string.size()); + r.reserve(1024); + r += string; + r += l1string; + r += string; + r += string; + } + COMPARE(r, r4); + } + +private: + const QLatin1String l1literal; + const QLatin1String l1string; + const QByteArray ba; + const QString string; + const std::string stdstring; + const QLatin1Char achar; + const QString r2, r3, r4, r5; + + // short cuts for results + QString r; + std::string stdr; +}; + +#undef P + +QTEST_MAIN(tst_QStringBuilder) + +#include "tst_bench_qstringbuilder.moc" diff --git a/tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt b/tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt index 4649e3408a..58af3c9dd3 100644 --- a/tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt +++ b/tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt @@ -1,12 +1,10 @@ -# Generated from qstringlist.pro. - ##################################################################### ## tst_bench_qstringlist Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qstringlist SOURCES - main.cpp + tst_bench_qstringlist.cpp PUBLIC_LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/text/qstringlist/main.cpp b/tests/benchmarks/corelib/text/qstringlist/main.cpp deleted file mode 100644 index 5c54bcebc5..0000000000 --- a/tests/benchmarks/corelib/text/qstringlist/main.cpp +++ /dev/null @@ -1,240 +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 -#include - -class tst_QStringList: public QObject -{ - Q_OBJECT - -private slots: - void join() const; - void join_data() const; - - void removeDuplicates() const; - void removeDuplicates_data() const; - - void split_qlist_qbytearray() const; - void split_qlist_qbytearray_data() const { return split_data(); } - - void split_data() const; - void split_qlist_qstring() const; - void split_qlist_qstring_data() const { return split_data(); } - - void split_stdvector_stdstring() const; - void split_stdvector_stdstring_data() const { return split_data(); } - - void split_stdvector_stdwstring() const; - void split_stdvector_stdwstring_data() const { return split_data(); } - - void split_stdlist_stdstring() const; - void split_stdlist_stdstring_data() const { return split_data(); } - -private: - static QStringList populateList(const int count, const QString &unit); - static QString populateString(const int count, const QString &unit); -}; - -QStringList tst_QStringList::populateList(const int count, const QString &unit) -{ - QStringList retval; - - for (int i = 0; i < count; ++i) - retval.append(unit); - - return retval; -} - -QString tst_QStringList::populateString(const int count, const QString &unit) -{ - QString retval; - - for (int i = 0; i < count; ++i) { - retval.append(unit); - retval.append(QLatin1Char(':')); - } - - return retval; -} - -void tst_QStringList::join() const -{ - QFETCH(QStringList, input); - QFETCH(QString, separator); - - QBENCHMARK { - [[maybe_unused]] auto r = input.join(separator); - } -} - -void tst_QStringList::join_data() const -{ - QTest::addColumn("input"); - QTest::addColumn("separator"); - - QTest::newRow("") - << populateList(100, QLatin1String("unit")) - << QString(); - - QTest::newRow("") - << populateList(1000, QLatin1String("unit")) - << QString(); - - QTest::newRow("") - << populateList(10000, QLatin1String("unit")) - << QString(); - - QTest::newRow("") - << populateList(100000, QLatin1String("unit")) - << QString(); -} - -void tst_QStringList::removeDuplicates() const -{ - QFETCH(const QStringList, input); - - QBENCHMARK { - auto copy = input; - copy.removeDuplicates(); - } -} - -void tst_QStringList::removeDuplicates_data() const -{ - QTest::addColumn("input"); - - const QStringList s = {"one", "two", "three"}; - - QTest::addRow("empty") << QStringList(); - QTest::addRow("short-dup-0.00") << s; - QTest::addRow("short-dup-0.50") << (s + s); - QTest::addRow("short-dup-0.66") << (s + s + s); - QTest::addRow("short-dup-0.75") << (s + s + s + s); - - const QStringList l = []() { - QStringList result; - const int n = 1000; - result.reserve(n); - for (int i = 0; i < n; ++i) - result.push_back(QString::number(i)); - return result; - }(); - QTest::addRow("long-dup-0.00") << l; - QTest::addRow("long-dup-0.50") << (l + l); - QTest::addRow("long-dup-0.66") << (l + l + l); - QTest::addRow("long-dup-0.75") << (l + l + l + l); -} - -void tst_QStringList::split_data() const -{ - QTest::addColumn("input"); - QString unit = QLatin1String("unit") + QString(100, QLatin1Char('s')); - //QTest::newRow("") << populateString(10, unit); - QTest::newRow("") << populateString(100, unit); - //QTest::newRow("") << populateString(100, unit); - //QTest::newRow("") << populateString(1000, unit); - //QTest::newRow("") << populateString(10000, unit); -} - -void tst_QStringList::split_qlist_qbytearray() const -{ - QFETCH(QString, input); - const char splitChar = ':'; - QByteArray ba = input.toLatin1(); - - QBENCHMARK { - [[maybe_unused]] auto r = ba.split(splitChar); - } -} - -void tst_QStringList::split_qlist_qstring() const -{ - QFETCH(QString, input); - const QChar splitChar = ':'; - - QBENCHMARK { - [[maybe_unused]] auto r = input.split(splitChar); - } -} - -void tst_QStringList::split_stdvector_stdstring() const -{ - QFETCH(QString, input); - const char split_char = ':'; - std::string stdinput = input.toStdString(); - - QBENCHMARK { - std::istringstream split(stdinput); - std::vector token; - for (std::string each; - std::getline(split, each, split_char); - token.push_back(each)) - ; - } -} - -void tst_QStringList::split_stdvector_stdwstring() const -{ - QFETCH(QString, input); - const wchar_t split_char = ':'; - std::wstring stdinput = input.toStdWString(); - - QBENCHMARK { - std::wistringstream split(stdinput); - std::vector token; - for (std::wstring each; - std::getline(split, each, split_char); - token.push_back(each)) - ; - } -} - -void tst_QStringList::split_stdlist_stdstring() const -{ - QFETCH(QString, input); - const char split_char = ':'; - std::string stdinput = input.toStdString(); - - QBENCHMARK { - std::istringstream split(stdinput); - std::list token; - for (std::string each; - std::getline(split, each, split_char); - token.push_back(each)) - ; - } -} - -QTEST_MAIN(tst_QStringList) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/text/qstringlist/tst_bench_qstringlist.cpp b/tests/benchmarks/corelib/text/qstringlist/tst_bench_qstringlist.cpp new file mode 100644 index 0000000000..327f4dc1a1 --- /dev/null +++ b/tests/benchmarks/corelib/text/qstringlist/tst_bench_qstringlist.cpp @@ -0,0 +1,240 @@ +/**************************************************************************** +** +** 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 +#include + +class tst_QStringList: public QObject +{ + Q_OBJECT + +private slots: + void join() const; + void join_data() const; + + void removeDuplicates() const; + void removeDuplicates_data() const; + + void split_qlist_qbytearray() const; + void split_qlist_qbytearray_data() const { return split_data(); } + + void split_data() const; + void split_qlist_qstring() const; + void split_qlist_qstring_data() const { return split_data(); } + + void split_stdvector_stdstring() const; + void split_stdvector_stdstring_data() const { return split_data(); } + + void split_stdvector_stdwstring() const; + void split_stdvector_stdwstring_data() const { return split_data(); } + + void split_stdlist_stdstring() const; + void split_stdlist_stdstring_data() const { return split_data(); } + +private: + static QStringList populateList(const int count, const QString &unit); + static QString populateString(const int count, const QString &unit); +}; + +QStringList tst_QStringList::populateList(const int count, const QString &unit) +{ + QStringList retval; + + for (int i = 0; i < count; ++i) + retval.append(unit); + + return retval; +} + +QString tst_QStringList::populateString(const int count, const QString &unit) +{ + QString retval; + + for (int i = 0; i < count; ++i) { + retval.append(unit); + retval.append(QLatin1Char(':')); + } + + return retval; +} + +void tst_QStringList::join() const +{ + QFETCH(QStringList, input); + QFETCH(QString, separator); + + QBENCHMARK { + [[maybe_unused]] auto r = input.join(separator); + } +} + +void tst_QStringList::join_data() const +{ + QTest::addColumn("input"); + QTest::addColumn("separator"); + + QTest::newRow("") + << populateList(100, QLatin1String("unit")) + << QString(); + + QTest::newRow("") + << populateList(1000, QLatin1String("unit")) + << QString(); + + QTest::newRow("") + << populateList(10000, QLatin1String("unit")) + << QString(); + + QTest::newRow("") + << populateList(100000, QLatin1String("unit")) + << QString(); +} + +void tst_QStringList::removeDuplicates() const +{ + QFETCH(const QStringList, input); + + QBENCHMARK { + auto copy = input; + copy.removeDuplicates(); + } +} + +void tst_QStringList::removeDuplicates_data() const +{ + QTest::addColumn("input"); + + const QStringList s = {"one", "two", "three"}; + + QTest::addRow("empty") << QStringList(); + QTest::addRow("short-dup-0.00") << s; + QTest::addRow("short-dup-0.50") << (s + s); + QTest::addRow("short-dup-0.66") << (s + s + s); + QTest::addRow("short-dup-0.75") << (s + s + s + s); + + const QStringList l = []() { + QStringList result; + const int n = 1000; + result.reserve(n); + for (int i = 0; i < n; ++i) + result.push_back(QString::number(i)); + return result; + }(); + QTest::addRow("long-dup-0.00") << l; + QTest::addRow("long-dup-0.50") << (l + l); + QTest::addRow("long-dup-0.66") << (l + l + l); + QTest::addRow("long-dup-0.75") << (l + l + l + l); +} + +void tst_QStringList::split_data() const +{ + QTest::addColumn("input"); + QString unit = QLatin1String("unit") + QString(100, QLatin1Char('s')); + //QTest::newRow("") << populateString(10, unit); + QTest::newRow("") << populateString(100, unit); + //QTest::newRow("") << populateString(100, unit); + //QTest::newRow("") << populateString(1000, unit); + //QTest::newRow("") << populateString(10000, unit); +} + +void tst_QStringList::split_qlist_qbytearray() const +{ + QFETCH(QString, input); + const char splitChar = ':'; + QByteArray ba = input.toLatin1(); + + QBENCHMARK { + [[maybe_unused]] auto r = ba.split(splitChar); + } +} + +void tst_QStringList::split_qlist_qstring() const +{ + QFETCH(QString, input); + const QChar splitChar = ':'; + + QBENCHMARK { + [[maybe_unused]] auto r = input.split(splitChar); + } +} + +void tst_QStringList::split_stdvector_stdstring() const +{ + QFETCH(QString, input); + const char split_char = ':'; + std::string stdinput = input.toStdString(); + + QBENCHMARK { + std::istringstream split(stdinput); + std::vector token; + for (std::string each; + std::getline(split, each, split_char); + token.push_back(each)) + ; + } +} + +void tst_QStringList::split_stdvector_stdwstring() const +{ + QFETCH(QString, input); + const wchar_t split_char = ':'; + std::wstring stdinput = input.toStdWString(); + + QBENCHMARK { + std::wistringstream split(stdinput); + std::vector token; + for (std::wstring each; + std::getline(split, each, split_char); + token.push_back(each)) + ; + } +} + +void tst_QStringList::split_stdlist_stdstring() const +{ + QFETCH(QString, input); + const char split_char = ':'; + std::string stdinput = input.toStdString(); + + QBENCHMARK { + std::istringstream split(stdinput); + std::list token; + for (std::string each; + std::getline(split, each, split_char); + token.push_back(each)) + ; + } +} + +QTEST_MAIN(tst_QStringList) + +#include "tst_bench_qstringlist.moc" diff --git a/tests/benchmarks/corelib/text/qstringtokenizer/CMakeLists.txt b/tests/benchmarks/corelib/text/qstringtokenizer/CMakeLists.txt index c2bf848400..92dd6cec98 100644 --- a/tests/benchmarks/corelib/text/qstringtokenizer/CMakeLists.txt +++ b/tests/benchmarks/corelib/text/qstringtokenizer/CMakeLists.txt @@ -4,7 +4,7 @@ qt_internal_add_benchmark(tst_bench_qstringtokenizer SOURCES - main.cpp + tst_bench_qstringtokenizer.cpp PUBLIC_LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/text/qstringtokenizer/main.cpp b/tests/benchmarks/corelib/text/qstringtokenizer/main.cpp deleted file mode 100644 index 54f48d5ea5..0000000000 --- a/tests/benchmarks/corelib/text/qstringtokenizer/main.cpp +++ /dev/null @@ -1,145 +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 - -class tst_QStringTokenizer : public QObject -{ - Q_OBJECT - - void tokenize_data() const; - template - void tokenize() const; -private slots: - void tokenize_qlatin1string_qlatin1string_data() const { tokenize_data(); } - void tokenize_qlatin1string_qlatin1string() const { tokenize(); } - void tokenize_qstring_qstring_data() const { tokenize_data(); } - void tokenize_qstring_qstring() const { tokenize(); } - void tokenize_qlatin1string_qstring_data() const { tokenize_data(); } - void tokenize_qlatin1string_qstring() const { tokenize(); } - void tokenize_qstring_qlatin1string_data() const { tokenize_data(); } - void tokenize_qstring_qlatin1string() const { tokenize(); } -}; - -template -T fromByteArray(QByteArrayView v); - -template<> -QString fromByteArray(QByteArrayView v) -{ - return QString::fromLatin1(v); -} - -template<> -QLatin1String fromByteArray(QByteArrayView v) -{ - return QLatin1String(v.data(), v.size()); -} - -void tst_QStringTokenizer::tokenize_data() const -{ - QTest::addColumn("input"); - QTest::addColumn("separator"); - QTest::addColumn("caseSensitive"); - QTest::addColumn("expectedCount"); - - QByteArray shortSentence = "A seriously short sentence."; - QTest::addRow("short-sentence-spaces") << shortSentence << QByteArray(" ") << true << 4; - QTest::addRow("short-sentence-spaces-case-insensitive") - << shortSentence << QByteArray(" ") << false << 4; - - QTest::addRow("short-sentence-se") << shortSentence << QByteArray("se") << true << 3; - QTest::addRow("short-sentence-se-case-insensitive") - << shortSentence << QByteArray("Se") << false << 3; - - QFile file(":/data/lorem.txt"); - if (!file.open(QFile::ReadOnly)) - qFatal("Can't open lorem.txt"); - - const QByteArray content = file.readAll(); - QTest::addRow("lorem-ipsum-spaces") << content << QByteArray(" ") << true << 3250; - QTest::addRow("lorem-ipsum-spaces-case-insensitive") - << content << QByteArray(" ") << false << 3250; - - QTest::addRow("lorem-ipsum-l") << content << QByteArray("l") << true << 771; - QTest::addRow("lorem-ipsum-l-case-insensitive") - << content << QByteArray("l") << false << 772; - - QTest::addRow("lorem-ipsum-lo") << content << QByteArray("lo") << true << 130; - QTest::addRow("lorem-ipsum-lo-case-insensitive") - << content << QByteArray("lo") << false << 131; - - QTest::addRow("lorem-ipsum-lor") << content << QByteArray("lor") << true << 122; - QTest::addRow("lorem-ipsum-lor-case-insensitive") - << content << QByteArray("lor") << false << 123; - - QTest::addRow("lorem-ipsum-lore") << content << QByteArray("lore") << true << 73; - QTest::addRow("lorem-ipsum-lore-case-insensitive") - << content << QByteArray("lore") << false << 74; - - QTest::addRow("lorem-ipsum-lorem") << content << QByteArray("lorem") << true << 34; - QTest::addRow("lorem-ipsum-lorem-case-insensitive") - << content << QByteArray("lorem") << false << 35; - - QTest::addRow("lorem-ipsum-lorem i") << content << QByteArray("lorem i") << true << 5; - QTest::addRow("lorem-ipsum-lorem i-case-insensitive") - << content << QByteArray("lorem i") << false << 6; - - QTest::addRow("lorem-ipsum-et explicabo s") << content << QByteArray("et explicabo s") << true << 3; - QTest::addRow("lorem-ipsum-et explicabo s-case-insensitive") - << content << QByteArray("et explicabo s") << false << 3; -} - -template -void tst_QStringTokenizer::tokenize() const -{ - QFETCH(QByteArray, input); - QFETCH(QByteArray, separator); - QFETCH(bool, caseSensitive); - QFETCH(int, expectedCount); - - T haystack = fromByteArray(input); - U needle = fromByteArray(separator); - - const Qt::CaseSensitivity sensitivity = caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive; - QBENCHMARK { - QStringTokenizer tok(haystack, needle, sensitivity); - qsizetype count = 0; - for (auto res : tok) { - count++; - Q_UNUSED(res); - } - QCOMPARE(count, expectedCount); - } -} - -QTEST_MAIN(tst_QStringTokenizer) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/text/qstringtokenizer/tst_bench_qstringtokenizer.cpp b/tests/benchmarks/corelib/text/qstringtokenizer/tst_bench_qstringtokenizer.cpp new file mode 100644 index 0000000000..291b314a7f --- /dev/null +++ b/tests/benchmarks/corelib/text/qstringtokenizer/tst_bench_qstringtokenizer.cpp @@ -0,0 +1,145 @@ +/**************************************************************************** +** +** 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 + +class tst_QStringTokenizer : public QObject +{ + Q_OBJECT + + void tokenize_data() const; + template + void tokenize() const; +private slots: + void tokenize_qlatin1string_qlatin1string_data() const { tokenize_data(); } + void tokenize_qlatin1string_qlatin1string() const { tokenize(); } + void tokenize_qstring_qstring_data() const { tokenize_data(); } + void tokenize_qstring_qstring() const { tokenize(); } + void tokenize_qlatin1string_qstring_data() const { tokenize_data(); } + void tokenize_qlatin1string_qstring() const { tokenize(); } + void tokenize_qstring_qlatin1string_data() const { tokenize_data(); } + void tokenize_qstring_qlatin1string() const { tokenize(); } +}; + +template +T fromByteArray(QByteArrayView v); + +template<> +QString fromByteArray(QByteArrayView v) +{ + return QString::fromLatin1(v); +} + +template<> +QLatin1String fromByteArray(QByteArrayView v) +{ + return QLatin1String(v.data(), v.size()); +} + +void tst_QStringTokenizer::tokenize_data() const +{ + QTest::addColumn("input"); + QTest::addColumn("separator"); + QTest::addColumn("caseSensitive"); + QTest::addColumn("expectedCount"); + + QByteArray shortSentence = "A seriously short sentence."; + QTest::addRow("short-sentence-spaces") << shortSentence << QByteArray(" ") << true << 4; + QTest::addRow("short-sentence-spaces-case-insensitive") + << shortSentence << QByteArray(" ") << false << 4; + + QTest::addRow("short-sentence-se") << shortSentence << QByteArray("se") << true << 3; + QTest::addRow("short-sentence-se-case-insensitive") + << shortSentence << QByteArray("Se") << false << 3; + + QFile file(":/data/lorem.txt"); + if (!file.open(QFile::ReadOnly)) + qFatal("Can't open lorem.txt"); + + const QByteArray content = file.readAll(); + QTest::addRow("lorem-ipsum-spaces") << content << QByteArray(" ") << true << 3250; + QTest::addRow("lorem-ipsum-spaces-case-insensitive") + << content << QByteArray(" ") << false << 3250; + + QTest::addRow("lorem-ipsum-l") << content << QByteArray("l") << true << 771; + QTest::addRow("lorem-ipsum-l-case-insensitive") + << content << QByteArray("l") << false << 772; + + QTest::addRow("lorem-ipsum-lo") << content << QByteArray("lo") << true << 130; + QTest::addRow("lorem-ipsum-lo-case-insensitive") + << content << QByteArray("lo") << false << 131; + + QTest::addRow("lorem-ipsum-lor") << content << QByteArray("lor") << true << 122; + QTest::addRow("lorem-ipsum-lor-case-insensitive") + << content << QByteArray("lor") << false << 123; + + QTest::addRow("lorem-ipsum-lore") << content << QByteArray("lore") << true << 73; + QTest::addRow("lorem-ipsum-lore-case-insensitive") + << content << QByteArray("lore") << false << 74; + + QTest::addRow("lorem-ipsum-lorem") << content << QByteArray("lorem") << true << 34; + QTest::addRow("lorem-ipsum-lorem-case-insensitive") + << content << QByteArray("lorem") << false << 35; + + QTest::addRow("lorem-ipsum-lorem i") << content << QByteArray("lorem i") << true << 5; + QTest::addRow("lorem-ipsum-lorem i-case-insensitive") + << content << QByteArray("lorem i") << false << 6; + + QTest::addRow("lorem-ipsum-et explicabo s") << content << QByteArray("et explicabo s") << true << 3; + QTest::addRow("lorem-ipsum-et explicabo s-case-insensitive") + << content << QByteArray("et explicabo s") << false << 3; +} + +template +void tst_QStringTokenizer::tokenize() const +{ + QFETCH(QByteArray, input); + QFETCH(QByteArray, separator); + QFETCH(bool, caseSensitive); + QFETCH(int, expectedCount); + + T haystack = fromByteArray(input); + U needle = fromByteArray(separator); + + const Qt::CaseSensitivity sensitivity = caseSensitive ? Qt::CaseSensitive : Qt::CaseInsensitive; + QBENCHMARK { + QStringTokenizer tok(haystack, needle, sensitivity); + qsizetype count = 0; + for (auto res : tok) { + count++; + Q_UNUSED(res); + } + QCOMPARE(count, expectedCount); + } +} + +QTEST_MAIN(tst_QStringTokenizer) + +#include "tst_bench_qstringtokenizer.moc" diff --git a/tests/benchmarks/corelib/thread/qfuture/CMakeLists.txt b/tests/benchmarks/corelib/thread/qfuture/CMakeLists.txt index 4a737c62b8..d53e3f6728 100644 --- a/tests/benchmarks/corelib/thread/qfuture/CMakeLists.txt +++ b/tests/benchmarks/corelib/thread/qfuture/CMakeLists.txt @@ -5,7 +5,7 @@ qt_internal_add_benchmark(tst_bench_qfuture EXCEPTIONS SOURCES - tst_qfuture.cpp + tst_bench_qfuture.cpp PUBLIC_LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/thread/qfuture/tst_bench_qfuture.cpp b/tests/benchmarks/corelib/thread/qfuture/tst_bench_qfuture.cpp new file mode 100644 index 0000000000..17c2f20712 --- /dev/null +++ b/tests/benchmarks/corelib/thread/qfuture/tst_bench_qfuture.cpp @@ -0,0 +1,321 @@ +/**************************************************************************** +** +** 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 + +class tst_QFuture : public QObject +{ + Q_OBJECT + +private slots: + void makeReadyfuture(); +#ifndef QT_NO_EXCEPTIONS + void makeExceptionalFuture(); +#endif + void result(); + void results(); + void takeResult(); + void reportResult(); + void reportResults(); + void reportResultsManualProgress(); +#ifndef QT_NO_EXCEPTIONS + void reportException(); +#endif + void then(); + void thenVoid(); + void onCanceled(); + void onCanceledVoid(); +#ifndef QT_NO_EXCEPTIONS + void onFailed(); + void onFailedVoid(); + void thenOnFailed(); + void thenOnFailedVoid(); +#endif + void reportProgress(); + void progressMinimum(); + void progressMaximum(); + void progressValue(); + void progressText(); +}; + +void tst_QFuture::makeReadyfuture() +{ + QBENCHMARK { + auto future = QtFuture::makeReadyFuture(42); + Q_UNUSED(future); + } +} + +#ifndef QT_NO_EXCEPTIONS +void tst_QFuture::makeExceptionalFuture() +{ + QException e; + QBENCHMARK { + auto future = QtFuture::makeExceptionalFuture(e); + Q_UNUSED(future); + } +} +#endif + +void tst_QFuture::result() +{ + auto future = QtFuture::makeReadyFuture(42); + + QBENCHMARK { + auto value = future.result(); + Q_UNUSED(value); + } +} + +void tst_QFuture::results() +{ + QFutureInterface fi; + fi.reportStarted(); + + for (int i = 0; i < 1000; ++i) + fi.reportResult(i); + + fi.reportFinished(); + + auto future = fi.future(); + QBENCHMARK { + auto values = future.results(); + Q_UNUSED(values); + } +} + +void tst_QFuture::takeResult() +{ + QBENCHMARK { + auto future = QtFuture::makeReadyFuture(42); + auto value = future.takeResult(); + Q_UNUSED(value); + } +} + +void tst_QFuture::reportResult() +{ + QFutureInterface fi; + QBENCHMARK { + fi.reportResult(42); + } +} + +void tst_QFuture::reportResults() +{ + QFutureInterface fi; + QList values(1000); + std::iota(values.begin(), values.end(), 0); + QBENCHMARK { + fi.reportResults(values); + } +} + +void tst_QFuture::reportResultsManualProgress() +{ + QFutureInterface fi; + const int resultCount = 1000; + fi.setProgressRange(0, resultCount); + QBENCHMARK { + for (int i = 0; i < resultCount; ++i) + fi.reportResult(i); + } +} + +#ifndef QT_NO_EXCEPTIONS +void tst_QFuture::reportException() +{ + QException e; + QBENCHMARK { + QFutureInterface fi; + fi.reportException(e); + } +} +#endif + +void tst_QFuture::then() +{ + auto f = QtFuture::makeReadyFuture(42); + QBENCHMARK { + auto future = f.then([](int value) { return value; }); + Q_UNUSED(future); + } +} + +void tst_QFuture::thenVoid() +{ + auto f = QtFuture::makeReadyFuture(); + QBENCHMARK { + auto future = f.then([] {}); + Q_UNUSED(future); + } +} + +void tst_QFuture::onCanceled() +{ + QFutureInterface fi; + fi.reportStarted(); + fi.reportCanceled(); + fi.reportFinished(); + + QBENCHMARK { + auto future = fi.future().onCanceled([] { return 0; }); + Q_UNUSED(future); + } +} + +void tst_QFuture::onCanceledVoid() +{ + QFutureInterface fi; + fi.reportStarted(); + fi.reportCanceled(); + fi.reportFinished(); + + QBENCHMARK { + auto future = fi.future().onCanceled([] {}); + Q_UNUSED(future); + } +} + +#ifndef QT_NO_EXCEPTIONS +void tst_QFuture::onFailed() +{ + QException e; + auto f = QtFuture::makeExceptionalFuture(e); + QBENCHMARK { + auto future = f.onFailed([] { return 0; }); + Q_UNUSED(future); + } +} + +void tst_QFuture::onFailedVoid() +{ + QException e; + auto f = QtFuture::makeExceptionalFuture(e); + QBENCHMARK { + auto future = f.onFailed([] {}); + Q_UNUSED(future); + } +} + +void tst_QFuture::thenOnFailed() +{ + auto f = QtFuture::makeReadyFuture(42); + QBENCHMARK { + auto future = + f.then([](int) { throw std::runtime_error("error"); }).onFailed([] { return 0; }); + Q_UNUSED(future); + } +} + +void tst_QFuture::thenOnFailedVoid() +{ + auto f = QtFuture::makeReadyFuture(); + QBENCHMARK { + auto future = f.then([] { throw std::runtime_error("error"); }).onFailed([] {}); + Q_UNUSED(future); + } +} + +#endif + +void tst_QFuture::reportProgress() +{ + QFutureInterface fi; + fi.reportStarted(); + fi.reportFinished(); + QBENCHMARK { + for (int i = 0; i < 100; ++i) { + fi.setProgressValue(i); + } + } +} + +void tst_QFuture::progressMinimum() +{ + QFutureInterface fi; + fi.setProgressRange(0, 100); + fi.reportStarted(); + fi.reportFinished(); + auto future = fi.future(); + + QBENCHMARK { + auto value = future.progressMinimum(); + Q_UNUSED(value); + } +} + +void tst_QFuture::progressMaximum() +{ + QFutureInterface fi; + fi.setProgressRange(0, 100); + fi.reportStarted(); + fi.reportFinished(); + auto future = fi.future(); + + QBENCHMARK { + auto value = future.progressMaximum(); + Q_UNUSED(value); + } +} + +void tst_QFuture::progressValue() +{ + QFutureInterface fi; + fi.setProgressValue(50); + fi.reportStarted(); + fi.reportFinished(); + auto future = fi.future(); + + QBENCHMARK { + auto value = future.progressValue(); + Q_UNUSED(value); + } +} + +void tst_QFuture::progressText() +{ + QFutureInterface fi; + fi.setProgressValueAndText(50, "text"); + fi.reportStarted(); + fi.reportFinished(); + auto future = fi.future(); + + QBENCHMARK { + auto text = future.progressText(); + Q_UNUSED(text); + } +} + +QTEST_MAIN(tst_QFuture) + +#include "tst_bench_qfuture.moc" diff --git a/tests/benchmarks/corelib/thread/qfuture/tst_qfuture.cpp b/tests/benchmarks/corelib/thread/qfuture/tst_qfuture.cpp deleted file mode 100644 index c7a4ff24d9..0000000000 --- a/tests/benchmarks/corelib/thread/qfuture/tst_qfuture.cpp +++ /dev/null @@ -1,320 +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 - -class tst_QFuture : public QObject -{ - Q_OBJECT - -private slots: - void makeReadyfuture(); -#ifndef QT_NO_EXCEPTIONS - void makeExceptionalFuture(); -#endif - void result(); - void results(); - void takeResult(); - void reportResult(); - void reportResults(); - void reportResultsManualProgress(); -#ifndef QT_NO_EXCEPTIONS - void reportException(); -#endif - void then(); - void thenVoid(); - void onCanceled(); - void onCanceledVoid(); -#ifndef QT_NO_EXCEPTIONS - void onFailed(); - void onFailedVoid(); - void thenOnFailed(); - void thenOnFailedVoid(); -#endif - void reportProgress(); - void progressMinimum(); - void progressMaximum(); - void progressValue(); - void progressText(); -}; - -void tst_QFuture::makeReadyfuture() -{ - QBENCHMARK { - auto future = QtFuture::makeReadyFuture(42); - Q_UNUSED(future); - } -} - -#ifndef QT_NO_EXCEPTIONS -void tst_QFuture::makeExceptionalFuture() -{ - QException e; - QBENCHMARK { - auto future = QtFuture::makeExceptionalFuture(e); - Q_UNUSED(future); - } -} -#endif - -void tst_QFuture::result() -{ - auto future = QtFuture::makeReadyFuture(42); - - QBENCHMARK { - auto value = future.result(); - Q_UNUSED(value); - } -} - -void tst_QFuture::results() -{ - QFutureInterface fi; - fi.reportStarted(); - - for (int i = 0; i < 1000; ++i) - fi.reportResult(i); - - fi.reportFinished(); - - auto future = fi.future(); - QBENCHMARK { - auto values = future.results(); - Q_UNUSED(values); - } -} - -void tst_QFuture::takeResult() -{ - QBENCHMARK { - auto future = QtFuture::makeReadyFuture(42); - auto value = future.takeResult(); - Q_UNUSED(value); - } -} - -void tst_QFuture::reportResult() -{ - QFutureInterface fi; - QBENCHMARK { - fi.reportResult(42); - } -} - -void tst_QFuture::reportResults() -{ - QFutureInterface fi; - QList values(1000); - std::iota(values.begin(), values.end(), 0); - QBENCHMARK { - fi.reportResults(values); - } -} - -void tst_QFuture::reportResultsManualProgress() -{ - QFutureInterface fi; - const int resultCount = 1000; - fi.setProgressRange(0, resultCount); - QBENCHMARK { - for (int i = 0; i < resultCount; ++i) - fi.reportResult(i); - } -} - -#ifndef QT_NO_EXCEPTIONS -void tst_QFuture::reportException() -{ - QException e; - QBENCHMARK { - QFutureInterface fi; - fi.reportException(e); - } -} -#endif - -void tst_QFuture::then() -{ - auto f = QtFuture::makeReadyFuture(42); - QBENCHMARK { - auto future = f.then([](int value) { return value; }); - Q_UNUSED(future); - } -} - -void tst_QFuture::thenVoid() -{ - auto f = QtFuture::makeReadyFuture(); - QBENCHMARK { - auto future = f.then([] {}); - Q_UNUSED(future); - } -} - -void tst_QFuture::onCanceled() -{ - QFutureInterface fi; - fi.reportStarted(); - fi.reportCanceled(); - fi.reportFinished(); - - QBENCHMARK { - auto future = fi.future().onCanceled([] { return 0; }); - Q_UNUSED(future); - } -} - -void tst_QFuture::onCanceledVoid() -{ - QFutureInterface fi; - fi.reportStarted(); - fi.reportCanceled(); - fi.reportFinished(); - - QBENCHMARK { - auto future = fi.future().onCanceled([] {}); - Q_UNUSED(future); - } -} - -#ifndef QT_NO_EXCEPTIONS -void tst_QFuture::onFailed() -{ - QException e; - auto f = QtFuture::makeExceptionalFuture(e); - QBENCHMARK { - auto future = f.onFailed([] { return 0; }); - Q_UNUSED(future); - } -} - -void tst_QFuture::onFailedVoid() -{ - QException e; - auto f = QtFuture::makeExceptionalFuture(e); - QBENCHMARK { - auto future = f.onFailed([] {}); - Q_UNUSED(future); - } -} - -void tst_QFuture::thenOnFailed() -{ - auto f = QtFuture::makeReadyFuture(42); - QBENCHMARK { - auto future = - f.then([](int) { throw std::runtime_error("error"); }).onFailed([] { return 0; }); - Q_UNUSED(future); - } -} - -void tst_QFuture::thenOnFailedVoid() -{ - auto f = QtFuture::makeReadyFuture(); - QBENCHMARK { - auto future = f.then([] { throw std::runtime_error("error"); }).onFailed([] {}); - Q_UNUSED(future); - } -} - -#endif - -void tst_QFuture::reportProgress() -{ - QFutureInterface fi; - fi.reportStarted(); - fi.reportFinished(); - QBENCHMARK { - for (int i = 0; i < 100; ++i) { - fi.setProgressValue(i); - } - } -} - -void tst_QFuture::progressMinimum() -{ - QFutureInterface fi; - fi.setProgressRange(0, 100); - fi.reportStarted(); - fi.reportFinished(); - auto future = fi.future(); - - QBENCHMARK { - auto value = future.progressMinimum(); - Q_UNUSED(value); - } -} - -void tst_QFuture::progressMaximum() -{ - QFutureInterface fi; - fi.setProgressRange(0, 100); - fi.reportStarted(); - fi.reportFinished(); - auto future = fi.future(); - - QBENCHMARK { - auto value = future.progressMaximum(); - Q_UNUSED(value); - } -} - -void tst_QFuture::progressValue() -{ - QFutureInterface fi; - fi.setProgressValue(50); - fi.reportStarted(); - fi.reportFinished(); - auto future = fi.future(); - - QBENCHMARK { - auto value = future.progressValue(); - Q_UNUSED(value); - } -} - -void tst_QFuture::progressText() -{ - QFutureInterface fi; - fi.setProgressValueAndText(50, "text"); - fi.reportStarted(); - fi.reportFinished(); - auto future = fi.future(); - - QBENCHMARK { - auto text = future.progressText(); - Q_UNUSED(text); - } -} - -QTEST_MAIN(tst_QFuture) -#include "tst_qfuture.moc" diff --git a/tests/benchmarks/corelib/thread/qmutex/CMakeLists.txt b/tests/benchmarks/corelib/thread/qmutex/CMakeLists.txt index 923bfba117..d056a10568 100644 --- a/tests/benchmarks/corelib/thread/qmutex/CMakeLists.txt +++ b/tests/benchmarks/corelib/thread/qmutex/CMakeLists.txt @@ -1,16 +1,11 @@ -# Generated from qmutex.pro. - ##################################################################### ## tst_bench_qmutex Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qmutex SOURCES - tst_qmutex.cpp + tst_bench_qmutex.cpp PUBLIC_LIBRARIES Qt::CorePrivate Qt::Test ) - -#### Keys ignored in scope 1:.:.:qmutex.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/thread/qmutex/tst_bench_qmutex.cpp b/tests/benchmarks/corelib/thread/qmutex/tst_bench_qmutex.cpp new file mode 100644 index 0000000000..987612b7b2 --- /dev/null +++ b/tests/benchmarks/corelib/thread/qmutex/tst_bench_qmutex.cpp @@ -0,0 +1,454 @@ +/**************************************************************************** +** +** 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 + +//#define USE_SEM_T + +#if defined(Q_OS_UNIX) +#if !defined(USE_SEM_T) +# include +# include +typedef pthread_mutex_t NativeMutexType; +void NativeMutexInitialize(NativeMutexType *mutex) +{ + pthread_mutex_init(mutex, NULL); +} +void NativeMutexDestroy(NativeMutexType *mutex) +{ + pthread_mutex_destroy(mutex); +} +void NativeMutexLock(NativeMutexType *mutex) +{ + pthread_mutex_lock(mutex); +} +void NativeMutexUnlock(NativeMutexType *mutex) +{ + pthread_mutex_unlock(mutex); +} +#else +# include +typedef sem_t NativeMutexType; +void NativeMutexInitialize(NativeMutexType *mutex) +{ + sem_init(mutex, false, 1); +} +void NativeMutexDestroy(NativeMutexType *mutex) +{ + sem_destroy(mutex); +} +void NativeMutexLock(NativeMutexType *mutex) +{ + sem_wait(mutex); +} +void NativeMutexUnlock(NativeMutexType *mutex) +{ + sem_post(mutex); +} +#endif +#elif defined(Q_OS_WIN) +# define _WIN32_WINNT 0x0400 +# include +typedef CRITICAL_SECTION NativeMutexType; +void NativeMutexInitialize(NativeMutexType *mutex) +{ + InitializeCriticalSection(mutex); +} +void NativeMutexDestroy(NativeMutexType *mutex) +{ + DeleteCriticalSection(mutex); +} +void NativeMutexLock(NativeMutexType *mutex) +{ + EnterCriticalSection(mutex); +} +void NativeMutexUnlock(NativeMutexType *mutex) +{ + LeaveCriticalSection(mutex); +} +#endif + +class tst_QMutex : public QObject +{ + Q_OBJECT + + int threadCount; + +public: + // barriers for the contended tests + static QSemaphore semaphore1, semaphore2, semaphore3, semaphore4; + + tst_QMutex() + { + // at least 2 threads, even on single cpu/core machines + threadCount = qMax(2, QThread::idealThreadCount()); + qDebug("thread count: %d", threadCount); + } + +private slots: + void noThread_data(); + void noThread(); + + void constructionNative(); + void uncontendedNative(); + void constructionQMutex(); + void uncontendedQMutex(); + void uncontendedQMutexLocker(); + + void contendedNative_data(); + void contendedQMutex_data() { contendedNative_data(); } + void contendedQMutexLocker_data() { contendedNative_data(); } + + void contendedNative(); + void contendedQMutex(); + void contendedQMutexLocker(); +}; + +QSemaphore tst_QMutex::semaphore1; +QSemaphore tst_QMutex::semaphore2; +QSemaphore tst_QMutex::semaphore3; +QSemaphore tst_QMutex::semaphore4; + +void tst_QMutex::noThread_data() +{ + QTest::addColumn("t"); + + QTest::newRow("noLock") << 1; + QTest::newRow("QMutex") << 3; + QTest::newRow("QMutexLocker") << 4; +} + +void tst_QMutex::noThread() +{ + volatile int count = 0; + const int N = 5000000; + QMutex mtx; + + QFETCH(int, t); + switch(t) { + case 1: + QBENCHMARK { + count = 0; + for (int i = 0; i < N; i++) { + QtPrivate::volatilePreIncrement(count); + } + } + break; + case 3: + QBENCHMARK { + count = 0; + for (int i = 0; i < N; i++) { + mtx.lock(); + QtPrivate::volatilePreIncrement(count); + mtx.unlock(); + } + } + break; + case 4: + QBENCHMARK { + count = 0; + for (int i = 0; i < N; i++) { + QMutexLocker locker(&mtx); + QtPrivate::volatilePreIncrement(count); + } + } + break; + } + QCOMPARE(int(count), N); +} + +void tst_QMutex::constructionNative() +{ + QBENCHMARK { + NativeMutexType mutex; + NativeMutexInitialize(&mutex); + NativeMutexDestroy(&mutex); + } +} + +void tst_QMutex::uncontendedNative() +{ + NativeMutexType mutex; + NativeMutexInitialize(&mutex); + QBENCHMARK { + NativeMutexLock(&mutex); + NativeMutexUnlock(&mutex); + } + NativeMutexDestroy(&mutex); +} + +void tst_QMutex::constructionQMutex() +{ + QBENCHMARK { + QMutex mutex; + Q_UNUSED(mutex); + } +} + +void tst_QMutex::uncontendedQMutex() +{ + QMutex mutex; + QBENCHMARK { + mutex.lock(); + mutex.unlock(); + } +} + +void tst_QMutex::uncontendedQMutexLocker() +{ + QMutex mutex; + QBENCHMARK { + QMutexLocker locker(&mutex); + } +} + +void tst_QMutex::contendedNative_data() +{ + QTest::addColumn("iterations"); + QTest::addColumn("msleepDuration"); + QTest::addColumn("use2mutexes"); + + QTest::newRow("baseline") << 0 << -1 << false; + + QTest::newRow("no msleep, 1 mutex") << 1000 << -1 << false; + QTest::newRow("no msleep, 2 mutexes") << 1000 << -1 << true; + QTest::newRow("msleep(0), 1 mutex") << 1000 << 0 << false; + QTest::newRow("msleep(0), 2 mutexes") << 1000 << 0 << true; + QTest::newRow("msleep(1), 1 mutex") << 10 << 1 << false; + QTest::newRow("msleep(1), 2 mutexes") << 10 << 1 << true; + QTest::newRow("msleep(2), 1 mutex") << 10 << 2 << false; + QTest::newRow("msleep(2), 2 mutexes") << 10 << 2 << true; + QTest::newRow("msleep(10), 1 mutex") << 10 << 10 << false; + QTest::newRow("msleep(10), 2 mutexes") << 10 << 10 << true; +} + +class NativeMutexThread : public QThread +{ + NativeMutexType *mutex1, *mutex2; + int iterations, msleepDuration; + bool use2mutexes; +public: + bool done; + NativeMutexThread(NativeMutexType *mutex1, NativeMutexType *mutex2, int iterations, int msleepDuration, bool use2mutexes) + : mutex1(mutex1), mutex2(mutex2), iterations(iterations), msleepDuration(msleepDuration), use2mutexes(use2mutexes), done(false) + { } + void run() override + { + forever { + tst_QMutex::semaphore1.release(); + tst_QMutex::semaphore2.acquire(); + if (done) + break; + for (int i = 0; i < iterations; ++i) { + NativeMutexLock(mutex1); + if (use2mutexes) + NativeMutexLock(mutex2); + if (msleepDuration >= 0) + msleep(msleepDuration); + if (use2mutexes) + NativeMutexUnlock(mutex2); + NativeMutexUnlock(mutex1); + + QThread::yieldCurrentThread(); + } + tst_QMutex::semaphore3.release(); + tst_QMutex::semaphore4.acquire(); + } + } +}; + +void tst_QMutex::contendedNative() +{ + QFETCH(int, iterations); + QFETCH(int, msleepDuration); + QFETCH(bool, use2mutexes); + + NativeMutexType mutex1, mutex2; + NativeMutexInitialize(&mutex1); + NativeMutexInitialize(&mutex2); + + QList threads(threadCount); + for (int i = 0; i < threads.count(); ++i) { + threads[i] = new NativeMutexThread(&mutex1, &mutex2, iterations, msleepDuration, use2mutexes); + threads[i]->start(); + } + + QBENCHMARK { + semaphore1.acquire(threadCount); + semaphore2.release(threadCount); + semaphore3.acquire(threadCount); + semaphore4.release(threadCount); + } + + for (int i = 0; i < threads.count(); ++i) + threads[i]->done = true; + semaphore1.acquire(threadCount); + semaphore2.release(threadCount); + for (int i = 0; i < threads.count(); ++i) + threads[i]->wait(); + qDeleteAll(threads); + + NativeMutexDestroy(&mutex1); + NativeMutexDestroy(&mutex2); +} + +class QMutexThread : public QThread +{ + QMutex *mutex1, *mutex2; + int iterations, msleepDuration; + bool use2mutexes; +public: + bool done; + QMutexThread(QMutex *mutex1, QMutex *mutex2, int iterations, int msleepDuration, bool use2mutexes) + : mutex1(mutex1), mutex2(mutex2), iterations(iterations), msleepDuration(msleepDuration), use2mutexes(use2mutexes), done(false) + { } + void run() override + { + forever { + tst_QMutex::semaphore1.release(); + tst_QMutex::semaphore2.acquire(); + if (done) + break; + for (int i = 0; i < iterations; ++i) { + mutex1->lock(); + if (use2mutexes) + mutex2->lock(); + if (msleepDuration >= 0) + msleep(msleepDuration); + if (use2mutexes) + mutex2->unlock(); + mutex1->unlock(); + + QThread::yieldCurrentThread(); + } + tst_QMutex::semaphore3.release(); + tst_QMutex::semaphore4.acquire(); + } + } +}; + +void tst_QMutex::contendedQMutex() +{ + QFETCH(int, iterations); + QFETCH(int, msleepDuration); + QFETCH(bool, use2mutexes); + + QMutex mutex1, mutex2; + + QList threads(threadCount); + for (int i = 0; i < threads.count(); ++i) { + threads[i] = new QMutexThread(&mutex1, &mutex2, iterations, msleepDuration, use2mutexes); + threads[i]->start(); + } + + QBENCHMARK { + semaphore1.acquire(threadCount); + semaphore2.release(threadCount); + semaphore3.acquire(threadCount); + semaphore4.release(threadCount); + } + + for (int i = 0; i < threads.count(); ++i) + threads[i]->done = true; + semaphore1.acquire(threadCount); + semaphore2.release(threadCount); + for (int i = 0; i < threads.count(); ++i) + threads[i]->wait(); + qDeleteAll(threads); +} + +class QMutexLockerThread : public QThread +{ + QMutex *mutex1, *mutex2; + int iterations, msleepDuration; + bool use2mutexes; +public: + bool done; + QMutexLockerThread(QMutex *mutex1, QMutex *mutex2, int iterations, int msleepDuration, bool use2mutexes) + : mutex1(mutex1), mutex2(mutex2), iterations(iterations), msleepDuration(msleepDuration), use2mutexes(use2mutexes), done(false) + { } + void run() override + { + forever { + tst_QMutex::semaphore1.release(); + tst_QMutex::semaphore2.acquire(); + if (done) + break; + for (int i = 0; i < iterations; ++i) { + { + QMutexLocker locker1(mutex1); + QMutexLocker locker2(use2mutexes ? mutex2 : 0); + if (msleepDuration >= 0) + msleep(msleepDuration); + } + + QThread::yieldCurrentThread(); + } + tst_QMutex::semaphore3.release(); + tst_QMutex::semaphore4.acquire(); + } + } +}; + +void tst_QMutex::contendedQMutexLocker() +{ + QFETCH(int, iterations); + QFETCH(int, msleepDuration); + QFETCH(bool, use2mutexes); + + QMutex mutex1, mutex2; + + QList threads(threadCount); + for (int i = 0; i < threads.count(); ++i) { + threads[i] = new QMutexLockerThread(&mutex1, &mutex2, iterations, msleepDuration, use2mutexes); + threads[i]->start(); + } + + QBENCHMARK { + semaphore1.acquire(threadCount); + semaphore2.release(threadCount); + semaphore3.acquire(threadCount); + semaphore4.release(threadCount); + } + + for (int i = 0; i < threads.count(); ++i) + threads[i]->done = true; + semaphore1.acquire(threadCount); + semaphore2.release(threadCount); + for (int i = 0; i < threads.count(); ++i) + threads[i]->wait(); + qDeleteAll(threads); +} + +QTEST_MAIN(tst_QMutex) + +#include "tst_bench_qmutex.moc" diff --git a/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp b/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp deleted file mode 100644 index 9b14cbca5d..0000000000 --- a/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp +++ /dev/null @@ -1,453 +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 - -//#define USE_SEM_T - -#if defined(Q_OS_UNIX) -#if !defined(USE_SEM_T) -# include -# include -typedef pthread_mutex_t NativeMutexType; -void NativeMutexInitialize(NativeMutexType *mutex) -{ - pthread_mutex_init(mutex, NULL); -} -void NativeMutexDestroy(NativeMutexType *mutex) -{ - pthread_mutex_destroy(mutex); -} -void NativeMutexLock(NativeMutexType *mutex) -{ - pthread_mutex_lock(mutex); -} -void NativeMutexUnlock(NativeMutexType *mutex) -{ - pthread_mutex_unlock(mutex); -} -#else -# include -typedef sem_t NativeMutexType; -void NativeMutexInitialize(NativeMutexType *mutex) -{ - sem_init(mutex, false, 1); -} -void NativeMutexDestroy(NativeMutexType *mutex) -{ - sem_destroy(mutex); -} -void NativeMutexLock(NativeMutexType *mutex) -{ - sem_wait(mutex); -} -void NativeMutexUnlock(NativeMutexType *mutex) -{ - sem_post(mutex); -} -#endif -#elif defined(Q_OS_WIN) -# define _WIN32_WINNT 0x0400 -# include -typedef CRITICAL_SECTION NativeMutexType; -void NativeMutexInitialize(NativeMutexType *mutex) -{ - InitializeCriticalSection(mutex); -} -void NativeMutexDestroy(NativeMutexType *mutex) -{ - DeleteCriticalSection(mutex); -} -void NativeMutexLock(NativeMutexType *mutex) -{ - EnterCriticalSection(mutex); -} -void NativeMutexUnlock(NativeMutexType *mutex) -{ - LeaveCriticalSection(mutex); -} -#endif - -class tst_QMutex : public QObject -{ - Q_OBJECT - - int threadCount; - -public: - // barriers for the contended tests - static QSemaphore semaphore1, semaphore2, semaphore3, semaphore4; - - tst_QMutex() - { - // at least 2 threads, even on single cpu/core machines - threadCount = qMax(2, QThread::idealThreadCount()); - qDebug("thread count: %d", threadCount); - } - -private slots: - void noThread_data(); - void noThread(); - - void constructionNative(); - void uncontendedNative(); - void constructionQMutex(); - void uncontendedQMutex(); - void uncontendedQMutexLocker(); - - void contendedNative_data(); - void contendedQMutex_data() { contendedNative_data(); } - void contendedQMutexLocker_data() { contendedNative_data(); } - - void contendedNative(); - void contendedQMutex(); - void contendedQMutexLocker(); -}; - -QSemaphore tst_QMutex::semaphore1; -QSemaphore tst_QMutex::semaphore2; -QSemaphore tst_QMutex::semaphore3; -QSemaphore tst_QMutex::semaphore4; - -void tst_QMutex::noThread_data() -{ - QTest::addColumn("t"); - - QTest::newRow("noLock") << 1; - QTest::newRow("QMutex") << 3; - QTest::newRow("QMutexLocker") << 4; -} - -void tst_QMutex::noThread() -{ - volatile int count = 0; - const int N = 5000000; - QMutex mtx; - - QFETCH(int, t); - switch(t) { - case 1: - QBENCHMARK { - count = 0; - for (int i = 0; i < N; i++) { - QtPrivate::volatilePreIncrement(count); - } - } - break; - case 3: - QBENCHMARK { - count = 0; - for (int i = 0; i < N; i++) { - mtx.lock(); - QtPrivate::volatilePreIncrement(count); - mtx.unlock(); - } - } - break; - case 4: - QBENCHMARK { - count = 0; - for (int i = 0; i < N; i++) { - QMutexLocker locker(&mtx); - QtPrivate::volatilePreIncrement(count); - } - } - break; - } - QCOMPARE(int(count), N); -} - -void tst_QMutex::constructionNative() -{ - QBENCHMARK { - NativeMutexType mutex; - NativeMutexInitialize(&mutex); - NativeMutexDestroy(&mutex); - } -} - -void tst_QMutex::uncontendedNative() -{ - NativeMutexType mutex; - NativeMutexInitialize(&mutex); - QBENCHMARK { - NativeMutexLock(&mutex); - NativeMutexUnlock(&mutex); - } - NativeMutexDestroy(&mutex); -} - -void tst_QMutex::constructionQMutex() -{ - QBENCHMARK { - QMutex mutex; - Q_UNUSED(mutex); - } -} - -void tst_QMutex::uncontendedQMutex() -{ - QMutex mutex; - QBENCHMARK { - mutex.lock(); - mutex.unlock(); - } -} - -void tst_QMutex::uncontendedQMutexLocker() -{ - QMutex mutex; - QBENCHMARK { - QMutexLocker locker(&mutex); - } -} - -void tst_QMutex::contendedNative_data() -{ - QTest::addColumn("iterations"); - QTest::addColumn("msleepDuration"); - QTest::addColumn("use2mutexes"); - - QTest::newRow("baseline") << 0 << -1 << false; - - QTest::newRow("no msleep, 1 mutex") << 1000 << -1 << false; - QTest::newRow("no msleep, 2 mutexes") << 1000 << -1 << true; - QTest::newRow("msleep(0), 1 mutex") << 1000 << 0 << false; - QTest::newRow("msleep(0), 2 mutexes") << 1000 << 0 << true; - QTest::newRow("msleep(1), 1 mutex") << 10 << 1 << false; - QTest::newRow("msleep(1), 2 mutexes") << 10 << 1 << true; - QTest::newRow("msleep(2), 1 mutex") << 10 << 2 << false; - QTest::newRow("msleep(2), 2 mutexes") << 10 << 2 << true; - QTest::newRow("msleep(10), 1 mutex") << 10 << 10 << false; - QTest::newRow("msleep(10), 2 mutexes") << 10 << 10 << true; -} - -class NativeMutexThread : public QThread -{ - NativeMutexType *mutex1, *mutex2; - int iterations, msleepDuration; - bool use2mutexes; -public: - bool done; - NativeMutexThread(NativeMutexType *mutex1, NativeMutexType *mutex2, int iterations, int msleepDuration, bool use2mutexes) - : mutex1(mutex1), mutex2(mutex2), iterations(iterations), msleepDuration(msleepDuration), use2mutexes(use2mutexes), done(false) - { } - void run() override - { - forever { - tst_QMutex::semaphore1.release(); - tst_QMutex::semaphore2.acquire(); - if (done) - break; - for (int i = 0; i < iterations; ++i) { - NativeMutexLock(mutex1); - if (use2mutexes) - NativeMutexLock(mutex2); - if (msleepDuration >= 0) - msleep(msleepDuration); - if (use2mutexes) - NativeMutexUnlock(mutex2); - NativeMutexUnlock(mutex1); - - QThread::yieldCurrentThread(); - } - tst_QMutex::semaphore3.release(); - tst_QMutex::semaphore4.acquire(); - } - } -}; - -void tst_QMutex::contendedNative() -{ - QFETCH(int, iterations); - QFETCH(int, msleepDuration); - QFETCH(bool, use2mutexes); - - NativeMutexType mutex1, mutex2; - NativeMutexInitialize(&mutex1); - NativeMutexInitialize(&mutex2); - - QList threads(threadCount); - for (int i = 0; i < threads.count(); ++i) { - threads[i] = new NativeMutexThread(&mutex1, &mutex2, iterations, msleepDuration, use2mutexes); - threads[i]->start(); - } - - QBENCHMARK { - semaphore1.acquire(threadCount); - semaphore2.release(threadCount); - semaphore3.acquire(threadCount); - semaphore4.release(threadCount); - } - - for (int i = 0; i < threads.count(); ++i) - threads[i]->done = true; - semaphore1.acquire(threadCount); - semaphore2.release(threadCount); - for (int i = 0; i < threads.count(); ++i) - threads[i]->wait(); - qDeleteAll(threads); - - NativeMutexDestroy(&mutex1); - NativeMutexDestroy(&mutex2); -} - -class QMutexThread : public QThread -{ - QMutex *mutex1, *mutex2; - int iterations, msleepDuration; - bool use2mutexes; -public: - bool done; - QMutexThread(QMutex *mutex1, QMutex *mutex2, int iterations, int msleepDuration, bool use2mutexes) - : mutex1(mutex1), mutex2(mutex2), iterations(iterations), msleepDuration(msleepDuration), use2mutexes(use2mutexes), done(false) - { } - void run() override - { - forever { - tst_QMutex::semaphore1.release(); - tst_QMutex::semaphore2.acquire(); - if (done) - break; - for (int i = 0; i < iterations; ++i) { - mutex1->lock(); - if (use2mutexes) - mutex2->lock(); - if (msleepDuration >= 0) - msleep(msleepDuration); - if (use2mutexes) - mutex2->unlock(); - mutex1->unlock(); - - QThread::yieldCurrentThread(); - } - tst_QMutex::semaphore3.release(); - tst_QMutex::semaphore4.acquire(); - } - } -}; - -void tst_QMutex::contendedQMutex() -{ - QFETCH(int, iterations); - QFETCH(int, msleepDuration); - QFETCH(bool, use2mutexes); - - QMutex mutex1, mutex2; - - QList threads(threadCount); - for (int i = 0; i < threads.count(); ++i) { - threads[i] = new QMutexThread(&mutex1, &mutex2, iterations, msleepDuration, use2mutexes); - threads[i]->start(); - } - - QBENCHMARK { - semaphore1.acquire(threadCount); - semaphore2.release(threadCount); - semaphore3.acquire(threadCount); - semaphore4.release(threadCount); - } - - for (int i = 0; i < threads.count(); ++i) - threads[i]->done = true; - semaphore1.acquire(threadCount); - semaphore2.release(threadCount); - for (int i = 0; i < threads.count(); ++i) - threads[i]->wait(); - qDeleteAll(threads); -} - -class QMutexLockerThread : public QThread -{ - QMutex *mutex1, *mutex2; - int iterations, msleepDuration; - bool use2mutexes; -public: - bool done; - QMutexLockerThread(QMutex *mutex1, QMutex *mutex2, int iterations, int msleepDuration, bool use2mutexes) - : mutex1(mutex1), mutex2(mutex2), iterations(iterations), msleepDuration(msleepDuration), use2mutexes(use2mutexes), done(false) - { } - void run() override - { - forever { - tst_QMutex::semaphore1.release(); - tst_QMutex::semaphore2.acquire(); - if (done) - break; - for (int i = 0; i < iterations; ++i) { - { - QMutexLocker locker1(mutex1); - QMutexLocker locker2(use2mutexes ? mutex2 : 0); - if (msleepDuration >= 0) - msleep(msleepDuration); - } - - QThread::yieldCurrentThread(); - } - tst_QMutex::semaphore3.release(); - tst_QMutex::semaphore4.acquire(); - } - } -}; - -void tst_QMutex::contendedQMutexLocker() -{ - QFETCH(int, iterations); - QFETCH(int, msleepDuration); - QFETCH(bool, use2mutexes); - - QMutex mutex1, mutex2; - - QList threads(threadCount); - for (int i = 0; i < threads.count(); ++i) { - threads[i] = new QMutexLockerThread(&mutex1, &mutex2, iterations, msleepDuration, use2mutexes); - threads[i]->start(); - } - - QBENCHMARK { - semaphore1.acquire(threadCount); - semaphore2.release(threadCount); - semaphore3.acquire(threadCount); - semaphore4.release(threadCount); - } - - for (int i = 0; i < threads.count(); ++i) - threads[i]->done = true; - semaphore1.acquire(threadCount); - semaphore2.release(threadCount); - for (int i = 0; i < threads.count(); ++i) - threads[i]->wait(); - qDeleteAll(threads); -} - -QTEST_MAIN(tst_QMutex) -#include "tst_qmutex.moc" diff --git a/tests/benchmarks/corelib/thread/qreadwritelock/CMakeLists.txt b/tests/benchmarks/corelib/thread/qreadwritelock/CMakeLists.txt index 79d3a2f879..901f9609bc 100644 --- a/tests/benchmarks/corelib/thread/qreadwritelock/CMakeLists.txt +++ b/tests/benchmarks/corelib/thread/qreadwritelock/CMakeLists.txt @@ -1,16 +1,11 @@ -# Generated from qreadwritelock.pro. - ##################################################################### ## tst_bench_qreadwritelock Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qreadwritelock SOURCES - tst_qreadwritelock.cpp + tst_bench_qreadwritelock.cpp PUBLIC_LIBRARIES Qt::CorePrivate Qt::Test ) - -#### Keys ignored in scope 1:.:.:qreadwritelock.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/thread/qreadwritelock/tst_bench_qreadwritelock.cpp b/tests/benchmarks/corelib/thread/qreadwritelock/tst_bench_qreadwritelock.cpp new file mode 100644 index 0000000000..f0ec45e267 --- /dev/null +++ b/tests/benchmarks/corelib/thread/qreadwritelock/tst_bench_qreadwritelock.cpp @@ -0,0 +1,259 @@ +/**************************************************************************** +** +** Copyright (C) 2016 Olivier Goffart +** 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 +#if __has_include() +#if __cplusplus > 201103L +#include +#endif +#endif +#include + +// Wrapers that take pointers instead of reference to have the same interface as Qt +template +struct LockerWrapper : T +{ + LockerWrapper(typename T::mutex_type *mtx) + : T(*mtx) + { + } +}; + +int threadCount; + +class tst_QReadWriteLock : public QObject +{ + Q_OBJECT +public: + tst_QReadWriteLock() + { + // at least 2 threads, even on single cpu/core machines + threadCount = qMax(2, QThread::idealThreadCount()); + qDebug("thread count: %d", threadCount); + } + +private slots: + void uncontended_data(); + void uncontended(); + void readOnly_data(); + void readOnly(); + void writeOnly_data(); + void writeOnly(); + // void readWrite(); +}; + +struct FunctionPtrHolder +{ + FunctionPtrHolder(QFunctionPointer value = nullptr) + : value(value) + { + } + QFunctionPointer value; +}; +Q_DECLARE_METATYPE(FunctionPtrHolder) + +struct FakeLock +{ + FakeLock(volatile int *i) { *i = 0; } +}; + +enum { Iterations = 1000000 }; + +template +void testUncontended() +{ + Mutex lock; + QBENCHMARK { + for (int i = 0; i < Iterations; ++i) { + Locker locker(&lock); + } + } +} + +void tst_QReadWriteLock::uncontended_data() +{ + QTest::addColumn("holder"); + + QTest::newRow("nothing") << FunctionPtrHolder(testUncontended); + QTest::newRow("QMutex") << FunctionPtrHolder(testUncontended>); + QTest::newRow("QReadWriteLock, read") + << FunctionPtrHolder(testUncontended); + QTest::newRow("QReadWriteLock, write") + << FunctionPtrHolder(testUncontended); + QTest::newRow("std::mutex") << FunctionPtrHolder( + testUncontended>>); +#ifdef __cpp_lib_shared_mutex + QTest::newRow("std::shared_mutex, read") << FunctionPtrHolder( + testUncontended>>); + QTest::newRow("std::shared_mutex, write") << FunctionPtrHolder( + testUncontended>>); +#endif +#if defined __cpp_lib_shared_timed_mutex + QTest::newRow("std::shared_timed_mutex, read") << FunctionPtrHolder( + testUncontended>>); + QTest::newRow("std::shared_timed_mutex, write") << FunctionPtrHolder( + testUncontended>>); +#endif +} + +void tst_QReadWriteLock::uncontended() +{ + QFETCH(FunctionPtrHolder, holder); + holder.value(); +} + +static QHash global_hash; + +template +void testReadOnly() +{ + struct Thread : QThread + { + Mutex *lock; + void run() override + { + for (int i = 0; i < Iterations; ++i) { + QString s = QString::number(i); // Do something outside the lock + Locker locker(lock); + global_hash.contains(s); + } + } + }; + Mutex lock; + std::vector> threads; + for (int i = 0; i < threadCount; ++i) { + auto t = std::make_unique(); + t->lock = &lock; + threads.push_back(std::move(t)); + } + QBENCHMARK { + for (auto &t : threads) { + t->start(); + } + for (auto &t : threads) { + t->wait(); + } + } +} + +void tst_QReadWriteLock::readOnly_data() +{ + QTest::addColumn("holder"); + + QTest::newRow("nothing") << FunctionPtrHolder(testReadOnly); + QTest::newRow("QMutex") << FunctionPtrHolder(testReadOnly>); + QTest::newRow("QReadWriteLock") << FunctionPtrHolder(testReadOnly); + QTest::newRow("std::mutex") << FunctionPtrHolder( + testReadOnly>>); +#ifdef __cpp_lib_shared_mutex + QTest::newRow("std::shared_mutex") << FunctionPtrHolder( + testReadOnly>>); +#endif +#if defined __cpp_lib_shared_timed_mutex + QTest::newRow("std::shared_timed_mutex") << FunctionPtrHolder( + testReadOnly>>); +#endif +} + +void tst_QReadWriteLock::readOnly() +{ + QFETCH(FunctionPtrHolder, holder); + holder.value(); +} + +static QString global_string; + +template +void testWriteOnly() +{ + struct Thread : QThread + { + Mutex *lock; + void run() override + { + for (int i = 0; i < Iterations; ++i) { + QString s = QString::number(i); // Do something outside the lock + Locker locker(lock); + global_string = s; + } + } + }; + Mutex lock; + std::vector> threads; + for (int i = 0; i < threadCount; ++i) { + auto t = std::make_unique(); + t->lock = &lock; + threads.push_back(std::move(t)); + } + QBENCHMARK { + for (auto &t : threads) { + t->start(); + } + for (auto &t : threads) { + t->wait(); + } + } +} + +void tst_QReadWriteLock::writeOnly_data() +{ + QTest::addColumn("holder"); + + // QTest::newRow("nothing") << FunctionPtrHolder(testWriteOnly); + QTest::newRow("QMutex") << FunctionPtrHolder(testWriteOnly>); + QTest::newRow("QReadWriteLock") << FunctionPtrHolder(testWriteOnly); + QTest::newRow("std::mutex") << FunctionPtrHolder( + testWriteOnly>>); +#ifdef __cpp_lib_shared_mutex + QTest::newRow("std::shared_mutex") << FunctionPtrHolder( + testWriteOnly>>); +#endif +#if defined __cpp_lib_shared_timed_mutex + QTest::newRow("std::shared_timed_mutex") << FunctionPtrHolder( + testWriteOnly>>); +#endif +} + +void tst_QReadWriteLock::writeOnly() +{ + QFETCH(FunctionPtrHolder, holder); + holder.value(); +} + +QTEST_MAIN(tst_QReadWriteLock) +#include "tst_bench_qreadwritelock.moc" diff --git a/tests/benchmarks/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp b/tests/benchmarks/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp deleted file mode 100644 index 1018dae878..0000000000 --- a/tests/benchmarks/corelib/thread/qreadwritelock/tst_qreadwritelock.cpp +++ /dev/null @@ -1,259 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 Olivier Goffart -** 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 -#if __has_include() -#if __cplusplus > 201103L -#include -#endif -#endif -#include - -// Wrapers that take pointers instead of reference to have the same interface as Qt -template -struct LockerWrapper : T -{ - LockerWrapper(typename T::mutex_type *mtx) - : T(*mtx) - { - } -}; - -int threadCount; - -class tst_QReadWriteLock : public QObject -{ - Q_OBJECT -public: - tst_QReadWriteLock() - { - // at least 2 threads, even on single cpu/core machines - threadCount = qMax(2, QThread::idealThreadCount()); - qDebug("thread count: %d", threadCount); - } - -private slots: - void uncontended_data(); - void uncontended(); - void readOnly_data(); - void readOnly(); - void writeOnly_data(); - void writeOnly(); - // void readWrite(); -}; - -struct FunctionPtrHolder -{ - FunctionPtrHolder(QFunctionPointer value = nullptr) - : value(value) - { - } - QFunctionPointer value; -}; -Q_DECLARE_METATYPE(FunctionPtrHolder) - -struct FakeLock -{ - FakeLock(volatile int *i) { *i = 0; } -}; - -enum { Iterations = 1000000 }; - -template -void testUncontended() -{ - Mutex lock; - QBENCHMARK { - for (int i = 0; i < Iterations; ++i) { - Locker locker(&lock); - } - } -} - -void tst_QReadWriteLock::uncontended_data() -{ - QTest::addColumn("holder"); - - QTest::newRow("nothing") << FunctionPtrHolder(testUncontended); - QTest::newRow("QMutex") << FunctionPtrHolder(testUncontended>); - QTest::newRow("QReadWriteLock, read") - << FunctionPtrHolder(testUncontended); - QTest::newRow("QReadWriteLock, write") - << FunctionPtrHolder(testUncontended); - QTest::newRow("std::mutex") << FunctionPtrHolder( - testUncontended>>); -#ifdef __cpp_lib_shared_mutex - QTest::newRow("std::shared_mutex, read") << FunctionPtrHolder( - testUncontended>>); - QTest::newRow("std::shared_mutex, write") << FunctionPtrHolder( - testUncontended>>); -#endif -#if defined __cpp_lib_shared_timed_mutex - QTest::newRow("std::shared_timed_mutex, read") << FunctionPtrHolder( - testUncontended>>); - QTest::newRow("std::shared_timed_mutex, write") << FunctionPtrHolder( - testUncontended>>); -#endif -} - -void tst_QReadWriteLock::uncontended() -{ - QFETCH(FunctionPtrHolder, holder); - holder.value(); -} - -static QHash global_hash; - -template -void testReadOnly() -{ - struct Thread : QThread - { - Mutex *lock; - void run() override - { - for (int i = 0; i < Iterations; ++i) { - QString s = QString::number(i); // Do something outside the lock - Locker locker(lock); - global_hash.contains(s); - } - } - }; - Mutex lock; - std::vector> threads; - for (int i = 0; i < threadCount; ++i) { - auto t = std::make_unique(); - t->lock = &lock; - threads.push_back(std::move(t)); - } - QBENCHMARK { - for (auto &t : threads) { - t->start(); - } - for (auto &t : threads) { - t->wait(); - } - } -} - -void tst_QReadWriteLock::readOnly_data() -{ - QTest::addColumn("holder"); - - QTest::newRow("nothing") << FunctionPtrHolder(testReadOnly); - QTest::newRow("QMutex") << FunctionPtrHolder(testReadOnly>); - QTest::newRow("QReadWriteLock") << FunctionPtrHolder(testReadOnly); - QTest::newRow("std::mutex") << FunctionPtrHolder( - testReadOnly>>); -#ifdef __cpp_lib_shared_mutex - QTest::newRow("std::shared_mutex") << FunctionPtrHolder( - testReadOnly>>); -#endif -#if defined __cpp_lib_shared_timed_mutex - QTest::newRow("std::shared_timed_mutex") << FunctionPtrHolder( - testReadOnly>>); -#endif -} - -void tst_QReadWriteLock::readOnly() -{ - QFETCH(FunctionPtrHolder, holder); - holder.value(); -} - -static QString global_string; - -template -void testWriteOnly() -{ - struct Thread : QThread - { - Mutex *lock; - void run() override - { - for (int i = 0; i < Iterations; ++i) { - QString s = QString::number(i); // Do something outside the lock - Locker locker(lock); - global_string = s; - } - } - }; - Mutex lock; - std::vector> threads; - for (int i = 0; i < threadCount; ++i) { - auto t = std::make_unique(); - t->lock = &lock; - threads.push_back(std::move(t)); - } - QBENCHMARK { - for (auto &t : threads) { - t->start(); - } - for (auto &t : threads) { - t->wait(); - } - } -} - -void tst_QReadWriteLock::writeOnly_data() -{ - QTest::addColumn("holder"); - - // QTest::newRow("nothing") << FunctionPtrHolder(testWriteOnly); - QTest::newRow("QMutex") << FunctionPtrHolder(testWriteOnly>); - QTest::newRow("QReadWriteLock") << FunctionPtrHolder(testWriteOnly); - QTest::newRow("std::mutex") << FunctionPtrHolder( - testWriteOnly>>); -#ifdef __cpp_lib_shared_mutex - QTest::newRow("std::shared_mutex") << FunctionPtrHolder( - testWriteOnly>>); -#endif -#if defined __cpp_lib_shared_timed_mutex - QTest::newRow("std::shared_timed_mutex") << FunctionPtrHolder( - testWriteOnly>>); -#endif -} - -void tst_QReadWriteLock::writeOnly() -{ - QFETCH(FunctionPtrHolder, holder); - holder.value(); -} - -QTEST_MAIN(tst_QReadWriteLock) -#include "tst_qreadwritelock.moc" diff --git a/tests/benchmarks/corelib/thread/qthreadpool/CMakeLists.txt b/tests/benchmarks/corelib/thread/qthreadpool/CMakeLists.txt index 7b0c81891e..0d1f145e25 100644 --- a/tests/benchmarks/corelib/thread/qthreadpool/CMakeLists.txt +++ b/tests/benchmarks/corelib/thread/qthreadpool/CMakeLists.txt @@ -1,15 +1,10 @@ -# Generated from qthreadpool.pro. - ##################################################################### ## tst_bench_qthreadpool Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qthreadpool SOURCES - tst_qthreadpool.cpp + tst_bench_qthreadpool.cpp PUBLIC_LIBRARIES Qt::Test ) - -#### Keys ignored in scope 1:.:.:qthreadpool.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/thread/qthreadpool/tst_bench_qthreadpool.cpp b/tests/benchmarks/corelib/thread/qthreadpool/tst_bench_qthreadpool.cpp new file mode 100644 index 0000000000..a64dbd15c9 --- /dev/null +++ b/tests/benchmarks/corelib/thread/qthreadpool/tst_bench_qthreadpool.cpp @@ -0,0 +1,80 @@ +/**************************************************************************** +** +** Copyright (C) 2013 David Faure +** 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_QThreadPool : public QObject +{ + Q_OBJECT + +public: + tst_QThreadPool(); + ~tst_QThreadPool(); + +private slots: + void startRunnables(); + void activeThreadCount(); +}; + +tst_QThreadPool::tst_QThreadPool() +{ +} + +tst_QThreadPool::~tst_QThreadPool() +{ +} + +class NoOpRunnable : public QRunnable +{ +public: + void run() override { + } +}; + +void tst_QThreadPool::startRunnables() +{ + QThreadPool threadPool; + threadPool.setMaxThreadCount(10); + QBENCHMARK { + threadPool.start(new NoOpRunnable()); + } +} + +void tst_QThreadPool::activeThreadCount() +{ + QThreadPool threadPool; + threadPool.start(new NoOpRunnable()); + QBENCHMARK { + QVERIFY(threadPool.activeThreadCount() <= 10); + } +} + +QTEST_MAIN(tst_QThreadPool) + +#include "tst_bench_qthreadpool.moc" diff --git a/tests/benchmarks/corelib/thread/qthreadpool/tst_qthreadpool.cpp b/tests/benchmarks/corelib/thread/qthreadpool/tst_qthreadpool.cpp deleted file mode 100644 index 10928e3afc..0000000000 --- a/tests/benchmarks/corelib/thread/qthreadpool/tst_qthreadpool.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2013 David Faure -** 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_QThreadPool : public QObject -{ - Q_OBJECT - -public: - tst_QThreadPool(); - ~tst_QThreadPool(); - -private slots: - void startRunnables(); - void activeThreadCount(); -}; - -tst_QThreadPool::tst_QThreadPool() -{ -} - -tst_QThreadPool::~tst_QThreadPool() -{ -} - -class NoOpRunnable : public QRunnable -{ -public: - void run() override { - } -}; - -void tst_QThreadPool::startRunnables() -{ - QThreadPool threadPool; - threadPool.setMaxThreadCount(10); - QBENCHMARK { - threadPool.start(new NoOpRunnable()); - } -} - -void tst_QThreadPool::activeThreadCount() -{ - QThreadPool threadPool; - threadPool.start(new NoOpRunnable()); - QBENCHMARK { - QVERIFY(threadPool.activeThreadCount() <= 10); - } -} - -QTEST_MAIN(tst_QThreadPool) -#include "tst_qthreadpool.moc" diff --git a/tests/benchmarks/corelib/thread/qthreadstorage/CMakeLists.txt b/tests/benchmarks/corelib/thread/qthreadstorage/CMakeLists.txt index 78ac072d35..7f5de4e9ab 100644 --- a/tests/benchmarks/corelib/thread/qthreadstorage/CMakeLists.txt +++ b/tests/benchmarks/corelib/thread/qthreadstorage/CMakeLists.txt @@ -1,15 +1,10 @@ -# Generated from qthreadstorage.pro. - ##################################################################### ## tst_bench_qthreadstorage Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qthreadstorage SOURCES - tst_qthreadstorage.cpp + tst_bench_qthreadstorage.cpp PUBLIC_LIBRARIES Qt::Test ) - -#### Keys ignored in scope 1:.:.:qthreadstorage.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/thread/qthreadstorage/tst_bench_qthreadstorage.cpp b/tests/benchmarks/corelib/thread/qthreadstorage/tst_bench_qthreadstorage.cpp new file mode 100644 index 0000000000..6230cd3187 --- /dev/null +++ b/tests/benchmarks/corelib/thread/qthreadstorage/tst_bench_qthreadstorage.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** 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 + +QThreadStorage dummy[8]; + +QThreadStorage tls1; + +class tst_QThreadStorage : public QObject +{ + Q_OBJECT + +public: + tst_QThreadStorage(); + virtual ~tst_QThreadStorage(); + +public slots: + void init(); + void cleanup(); + +private slots: + void construct(); + void get(); + void set(); +}; + +tst_QThreadStorage::tst_QThreadStorage() +{ +} + +tst_QThreadStorage::~tst_QThreadStorage() +{ +} + +void tst_QThreadStorage::init() +{ + dummy[1].setLocalData(new int(5)); + dummy[2].setLocalData(new int(4)); + dummy[3].setLocalData(new int(3)); + tls1.setLocalData(new QString()); +} + +void tst_QThreadStorage::cleanup() +{ +} + +void tst_QThreadStorage::construct() +{ + QBENCHMARK { + QThreadStorage ts; + } +} + + +void tst_QThreadStorage::get() +{ + QThreadStorage ts; + ts.setLocalData(new int(45)); + + int count = 0; + QBENCHMARK { + int *i = ts.localData(); + count += *i; + } + ts.setLocalData(0); +} + +void tst_QThreadStorage::set() +{ + QThreadStorage ts; + + int count = 0; + QBENCHMARK { + ts.setLocalData(new int(count)); + count++; + } + ts.setLocalData(0); +} + +QTEST_MAIN(tst_QThreadStorage) + +#include "tst_bench_qthreadstorage.moc" diff --git a/tests/benchmarks/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp b/tests/benchmarks/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp deleted file mode 100644 index c8f9f23c76..0000000000 --- a/tests/benchmarks/corelib/thread/qthreadstorage/tst_qthreadstorage.cpp +++ /dev/null @@ -1,109 +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 - -QThreadStorage dummy[8]; - -QThreadStorage tls1; - -class tst_QThreadStorage : public QObject -{ - Q_OBJECT - -public: - tst_QThreadStorage(); - virtual ~tst_QThreadStorage(); - -public slots: - void init(); - void cleanup(); - -private slots: - void construct(); - void get(); - void set(); -}; - -tst_QThreadStorage::tst_QThreadStorage() -{ -} - -tst_QThreadStorage::~tst_QThreadStorage() -{ -} - -void tst_QThreadStorage::init() -{ - dummy[1].setLocalData(new int(5)); - dummy[2].setLocalData(new int(4)); - dummy[3].setLocalData(new int(3)); - tls1.setLocalData(new QString()); -} - -void tst_QThreadStorage::cleanup() -{ -} - -void tst_QThreadStorage::construct() -{ - QBENCHMARK { - QThreadStorage ts; - } -} - - -void tst_QThreadStorage::get() -{ - QThreadStorage ts; - ts.setLocalData(new int(45)); - - int count = 0; - QBENCHMARK { - int *i = ts.localData(); - count += *i; - } - ts.setLocalData(0); -} - -void tst_QThreadStorage::set() -{ - QThreadStorage ts; - - int count = 0; - QBENCHMARK { - ts.setLocalData(new int(count)); - count++; - } - ts.setLocalData(0); -} - - -QTEST_MAIN(tst_QThreadStorage) -#include "tst_qthreadstorage.moc" diff --git a/tests/benchmarks/corelib/thread/qwaitcondition/CMakeLists.txt b/tests/benchmarks/corelib/thread/qwaitcondition/CMakeLists.txt index 68c6e88342..13814d7074 100644 --- a/tests/benchmarks/corelib/thread/qwaitcondition/CMakeLists.txt +++ b/tests/benchmarks/corelib/thread/qwaitcondition/CMakeLists.txt @@ -1,15 +1,10 @@ -# Generated from qwaitcondition.pro. - ##################################################################### ## tst_bench_qwaitcondition Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qwaitcondition SOURCES - tst_qwaitcondition.cpp + tst_bench_qwaitcondition.cpp PUBLIC_LIBRARIES Qt::Test ) - -#### Keys ignored in scope 1:.:.:qwaitcondition.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/thread/qwaitcondition/tst_bench_qwaitcondition.cpp b/tests/benchmarks/corelib/thread/qwaitcondition/tst_bench_qwaitcondition.cpp new file mode 100644 index 0000000000..19d3964c7a --- /dev/null +++ b/tests/benchmarks/corelib/thread/qwaitcondition/tst_bench_qwaitcondition.cpp @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** 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 tst_QWaitCondition : public QObject +{ + Q_OBJECT + +public: + tst_QWaitCondition() + { + } + +private slots: + void oscillate_mutex_data(); + void oscillate_mutex(); + void oscillate_writelock_data(); + void oscillate_writelock(); +}; + + +int turn; +const int threadCount = 10; +QWaitCondition cond; + +template +class OscillateThread : public QThread +{ +public: + Mutex *mutex; + int m_threadid; + int timeout; + + void run() override + { + for (int count = 0; count < 5000; ++count) { + + Locker lock(mutex); + while (m_threadid != turn) { + cond.wait(mutex, timeout); + } + turn = (turn+1) % threadCount; + cond.wakeAll(); + } + } +}; + +template +void oscillate(unsigned long timeout) { + + OscillateThread thrd[threadCount]; + Mutex m; + for (int i = 0; i < threadCount; ++i) { + thrd[i].mutex = &m; + thrd[i].m_threadid = i; + thrd[i].timeout = timeout; + } + + QBENCHMARK { + for (int i = 0; i < threadCount; ++i) { + thrd[i].start(); + } + for (int i = 0; i < threadCount; ++i) { + thrd[i].wait(); + } + } + +} + +void tst_QWaitCondition::oscillate_mutex_data() +{ + QTest::addColumn("timeout"); + + QTest::newRow("0") << 0ul; + QTest::newRow("1") << 1ul; + QTest::newRow("1000") << 1000ul; + QTest::newRow("forever") << ULONG_MAX; +} + +void tst_QWaitCondition::oscillate_mutex() +{ + QFETCH(unsigned long, timeout); + oscillate>(timeout); +} + +void tst_QWaitCondition::oscillate_writelock_data() +{ + oscillate_mutex_data(); +} + +void tst_QWaitCondition::oscillate_writelock() +{ + QFETCH(unsigned long, timeout); + oscillate(timeout); +} + +QTEST_MAIN(tst_QWaitCondition) + +#include "tst_bench_qwaitcondition.moc" diff --git a/tests/benchmarks/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp b/tests/benchmarks/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp deleted file mode 100644 index b87da463dc..0000000000 --- a/tests/benchmarks/corelib/thread/qwaitcondition/tst_qwaitcondition.cpp +++ /dev/null @@ -1,129 +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 tst_QWaitCondition : public QObject -{ - Q_OBJECT - -public: - tst_QWaitCondition() - { - } - -private slots: - void oscillate_mutex_data(); - void oscillate_mutex(); - void oscillate_writelock_data(); - void oscillate_writelock(); -}; - - -int turn; -const int threadCount = 10; -QWaitCondition cond; - -template -class OscillateThread : public QThread -{ -public: - Mutex *mutex; - int m_threadid; - int timeout; - - void run() override - { - for (int count = 0; count < 5000; ++count) { - - Locker lock(mutex); - while (m_threadid != turn) { - cond.wait(mutex, timeout); - } - turn = (turn+1) % threadCount; - cond.wakeAll(); - } - } -}; - -template -void oscillate(unsigned long timeout) { - - OscillateThread thrd[threadCount]; - Mutex m; - for (int i = 0; i < threadCount; ++i) { - thrd[i].mutex = &m; - thrd[i].m_threadid = i; - thrd[i].timeout = timeout; - } - - QBENCHMARK { - for (int i = 0; i < threadCount; ++i) { - thrd[i].start(); - } - for (int i = 0; i < threadCount; ++i) { - thrd[i].wait(); - } - } - -} - -void tst_QWaitCondition::oscillate_mutex_data() -{ - QTest::addColumn("timeout"); - - QTest::newRow("0") << 0ul; - QTest::newRow("1") << 1ul; - QTest::newRow("1000") << 1000ul; - QTest::newRow("forever") << ULONG_MAX; -} - -void tst_QWaitCondition::oscillate_mutex() -{ - QFETCH(unsigned long, timeout); - oscillate>(timeout); -} - -void tst_QWaitCondition::oscillate_writelock_data() -{ - oscillate_mutex_data(); -} - -void tst_QWaitCondition::oscillate_writelock() -{ - QFETCH(unsigned long, timeout); - oscillate(timeout); -} - - -QTEST_MAIN(tst_QWaitCondition) -#include "tst_qwaitcondition.moc" diff --git a/tests/benchmarks/corelib/time/qdatetime/CMakeLists.txt b/tests/benchmarks/corelib/time/qdatetime/CMakeLists.txt index 2585b0d25d..a9546f3cad 100644 --- a/tests/benchmarks/corelib/time/qdatetime/CMakeLists.txt +++ b/tests/benchmarks/corelib/time/qdatetime/CMakeLists.txt @@ -1,12 +1,10 @@ -# Generated from qdatetime.pro. - ##################################################################### ## tst_bench_qdatetime Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qdatetime SOURCES - main.cpp + tst_bench_qdatetime.cpp PUBLIC_LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/time/qdatetime/main.cpp b/tests/benchmarks/corelib/time/qdatetime/main.cpp deleted file mode 100644 index c6d2b84597..0000000000 --- a/tests/benchmarks/corelib/time/qdatetime/main.cpp +++ /dev/null @@ -1,574 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module 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 - -class tst_QDateTime : public QObject -{ - Q_OBJECT - - enum : qint64 - { - SECS_PER_DAY = 86400, - MSECS_PER_DAY = 86400000, - JULIAN_DAY_1950 = 2433283, - JULIAN_DAY_1960 = 2436935, - JULIAN_DAY_1970 = 2440588, // Epoch - JULIAN_DAY_2010 = 2455198, - JULIAN_DAY_2011 = 2455563, - JULIAN_DAY_2020 = 2458850, - JULIAN_DAY_2050 = 2469808, - JULIAN_DAY_2060 = 2473460 - }; - - static QList daily(qint64 start, qint64 end); - static QList norse(qint64 start, qint64 end); - -private Q_SLOTS: - void create(); - void isNull(); - void isValid(); - void date(); - void time(); - void timeSpec(); - void offsetFromUtc(); - void timeZoneAbbreviation(); - void toMSecsSinceEpoch(); - void toMSecsSinceEpoch1950(); - void toMSecsSinceEpoch2050(); - void toMSecsSinceEpochTz(); - void toMSecsSinceEpoch1950Tz(); - void toMSecsSinceEpoch2050Tz(); - void setDate(); - void setTime(); - void setTimeSpec(); - void setOffsetFromUtc(); - void setMSecsSinceEpoch(); - void setMSecsSinceEpochTz(); - void toString(); - void toStringTextFormat(); - void toStringIsoFormat(); - void addDays(); - void addDaysTz(); - void addMSecs(); - void addMSecsTz(); - void toTimeSpec(); - void toOffsetFromUtc(); - void daysTo(); - void msecsTo(); - void equivalent(); - void equivalentUtc(); - void lessThan(); - void lessThanUtc(); - void currentDateTime(); - void currentDate(); - void currentTime(); - void currentDateTimeUtc(); - void currentMSecsSinceEpoch(); - void fromString(); - void fromStringText(); - void fromStringIso(); - void fromMSecsSinceEpoch(); - void fromMSecsSinceEpochUtc(); - void fromMSecsSinceEpochTz(); -}; - -QList tst_QDateTime::daily(qint64 start, qint64 end) -{ - QList list; - list.reserve(end - start); - for (int jd = start; jd < end; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); - return list; -} - -QList tst_QDateTime::norse(qint64 start, qint64 end) -{ - const QTimeZone cet("Europe/Oslo"); - QList list; - list.reserve(end - start); - for (int jd = start; jd < end; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet)); - return list; -} - -void tst_QDateTime::create() -{ - QBENCHMARK { - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) { - QDateTime test(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)); - Q_UNUSED(test); - } - } -} - -void tst_QDateTime::isNull() -{ - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - test.isNull(); - } -} - -void tst_QDateTime::isValid() -{ - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - test.isValid(); - } -} - -void tst_QDateTime::date() -{ - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - test.date(); - } -} - -void tst_QDateTime::time() -{ - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - test.time(); - } -} - -void tst_QDateTime::timeSpec() -{ - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - test.timeSpec(); - } -} - -void tst_QDateTime::offsetFromUtc() -{ - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - test.offsetFromUtc(); - } -} - -void tst_QDateTime::timeZoneAbbreviation() -{ - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - test.timeZoneAbbreviation(); - } -} - -void tst_QDateTime::toMSecsSinceEpoch() -{ - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - test.toMSecsSinceEpoch(); - } -} - -void tst_QDateTime::toMSecsSinceEpoch1950() -{ - const auto list = daily(JULIAN_DAY_1950, JULIAN_DAY_1960); - QBENCHMARK { - for (const QDateTime &test : list) - test.toMSecsSinceEpoch(); - } -} - -void tst_QDateTime::toMSecsSinceEpoch2050() -{ - const auto list = daily(JULIAN_DAY_2050, JULIAN_DAY_2060); - QBENCHMARK { - for (const QDateTime &test : list) - test.toMSecsSinceEpoch(); - } -} - -void tst_QDateTime::toMSecsSinceEpochTz() -{ - qint64 result; - const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - result = test.toMSecsSinceEpoch(); - } - Q_UNUSED(result); -} - -void tst_QDateTime::toMSecsSinceEpoch1950Tz() -{ - qint64 result; - const auto list = norse(JULIAN_DAY_1950, JULIAN_DAY_1960); - QBENCHMARK { - for (const QDateTime &test : list) - result = test.toMSecsSinceEpoch(); - } - Q_UNUSED(result); -} - -void tst_QDateTime::toMSecsSinceEpoch2050Tz() -{ - qint64 result; - const auto list = norse(JULIAN_DAY_2050, JULIAN_DAY_2060); - QBENCHMARK { - for (const QDateTime &test : list) - result = test.toMSecsSinceEpoch(); - } - Q_UNUSED(result); -} - -void tst_QDateTime::setDate() -{ - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (QDateTime test : list) - test.setDate(QDate::fromJulianDay(JULIAN_DAY_2010)); - } -} - -void tst_QDateTime::setTime() -{ - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (QDateTime test : list) - test.setTime(QTime(12, 0, 0)); - } -} - -void tst_QDateTime::setTimeSpec() -{ - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (QDateTime test : list) - test.setTimeSpec(Qt::UTC); - } -} - -void tst_QDateTime::setOffsetFromUtc() -{ - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (QDateTime test : list) - test.setOffsetFromUtc(3600); - } -} - -void tst_QDateTime::setMSecsSinceEpoch() -{ - qint64 msecs = qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970 + 180) * MSECS_PER_DAY; - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (QDateTime test : list) - test.setMSecsSinceEpoch(msecs); - } -} - -void tst_QDateTime::setMSecsSinceEpochTz() -{ - const qint64 msecs = qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970 + 180) * MSECS_PER_DAY; - const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (QDateTime test : list) - test.setMSecsSinceEpoch(msecs); - } -} - -void tst_QDateTime::toString() -{ - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2011); - QBENCHMARK { - for (const QDateTime &test : list) - test.toString(QStringLiteral("yyy-MM-dd hh:mm:ss.zzz t")); - } -} - -void tst_QDateTime::toStringTextFormat() -{ - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2011); - QBENCHMARK { - for (const QDateTime &test : list) - test.toString(Qt::TextDate); - } -} - -void tst_QDateTime::toStringIsoFormat() -{ - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2011); - QBENCHMARK { - for (const QDateTime &test : list) - test.toString(Qt::ISODate); - } -} - -void tst_QDateTime::addDays() -{ - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QDateTime next; - QBENCHMARK { - for (const QDateTime &test : list) - next = test.addDays(1); - } - Q_UNUSED(next); -} - -void tst_QDateTime::addDaysTz() -{ - const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - QDateTime result = test.addDays(1); - } -} - -void tst_QDateTime::addMSecs() -{ - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QDateTime next; - QBENCHMARK { - for (const QDateTime &test : list) - next = test.addMSecs(1); - } - Q_UNUSED(next); -} - -void tst_QDateTime::addMSecsTz() -{ - const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - QDateTime result = test.addMSecs(1); - } -} - -void tst_QDateTime::toTimeSpec() -{ - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - test.toTimeSpec(Qt::UTC); - } -} - -void tst_QDateTime::toOffsetFromUtc() -{ - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - test.toOffsetFromUtc(3600); - } -} - -void tst_QDateTime::daysTo() -{ - const QDateTime other = QDateTime::fromMSecsSinceEpoch( - qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY); - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - test.daysTo(other); - } -} - -void tst_QDateTime::msecsTo() -{ - const QDateTime other = QDateTime::fromMSecsSinceEpoch( - qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY); - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - test.msecsTo(other); - } -} - -void tst_QDateTime::equivalent() -{ - bool result; - const QDateTime other = QDateTime::fromMSecsSinceEpoch( - qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY); - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - result = (test == other); - } - Q_UNUSED(result); -} - -void tst_QDateTime::equivalentUtc() -{ - bool result = false; - const QDateTime other = QDateTime::fromMSecsSinceEpoch( - qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, Qt::UTC); - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - result = (test == other); - } - Q_UNUSED(result); -} - -void tst_QDateTime::lessThan() -{ - bool result = false; - const QDateTime other = QDateTime::fromMSecsSinceEpoch( - qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY); - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - result = (test < other); - } - Q_UNUSED(result); -} - -void tst_QDateTime::lessThanUtc() -{ - bool result = false; - const QDateTime other = QDateTime::fromMSecsSinceEpoch( - qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, Qt::UTC); - const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); - QBENCHMARK { - for (const QDateTime &test : list) - result = (test < other); - } - Q_UNUSED(result); -} - -void tst_QDateTime::currentDateTime() -{ - QBENCHMARK { - for (int i = 0; i < 1000; ++i) - QDateTime::currentDateTime(); - } -} - -void tst_QDateTime::currentDate() -{ - QBENCHMARK { - for (int i = 0; i < 1000; ++i) - QDate::currentDate(); - } -} - -void tst_QDateTime::currentTime() -{ - QBENCHMARK { - for (int i = 0; i < 1000; ++i) - QTime::currentTime(); - } -} - -void tst_QDateTime::currentDateTimeUtc() -{ - QBENCHMARK { - for (int i = 0; i < 1000; ++i) - QDateTime::currentDateTimeUtc(); - } -} - -void tst_QDateTime::currentMSecsSinceEpoch() -{ - QBENCHMARK { - for (int i = 0; i < 1000; ++i) - QDateTime::currentMSecsSinceEpoch(); - } -} - -void tst_QDateTime::fromString() -{ - QString format = "yyyy-MM-dd hh:mm:ss.zzz"; - QString input = "2010-01-01 13:12:11.999"; - QVERIFY(QDateTime::fromString(input, format).isValid()); - QBENCHMARK { - for (int i = 0; i < 1000; ++i) - QDateTime::fromString(input, format); - } -} - -void tst_QDateTime::fromStringText() -{ - QString input = "Wed Jan 2 01:02:03.000 2013 GMT"; - QBENCHMARK { - for (int i = 0; i < 1000; ++i) - QDateTime::fromString(input, Qt::TextDate); - } -} - -void tst_QDateTime::fromStringIso() -{ - QString input = "2010-01-01T13:28:34.999Z"; - QBENCHMARK { - for (int i = 0; i < 1000; ++i) - QDateTime::fromString(input, Qt::ISODate); - } -} - -void tst_QDateTime::fromMSecsSinceEpoch() -{ - const int start = JULIAN_DAY_2010 - JULIAN_DAY_1970; - const int end = JULIAN_DAY_2020 - JULIAN_DAY_1970; - QBENCHMARK { - for (int jd = start; jd < end; ++jd) - QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, Qt::LocalTime); - } -} - -void tst_QDateTime::fromMSecsSinceEpochUtc() -{ - const int start = JULIAN_DAY_2010 - JULIAN_DAY_1970; - const int end = JULIAN_DAY_2020 - JULIAN_DAY_1970; - QBENCHMARK { - for (int jd = start; jd < end; ++jd) - QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, Qt::UTC); - } -} - -void tst_QDateTime::fromMSecsSinceEpochTz() -{ - const int start = JULIAN_DAY_2010 - JULIAN_DAY_1970; - const int end = JULIAN_DAY_2020 - JULIAN_DAY_1970; - const QTimeZone cet("Europe/Oslo"); - QBENCHMARK { - for (int jd = start; jd < end; ++jd) - QDateTime test = QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, cet); - } -} - -QTEST_MAIN(tst_QDateTime) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/time/qdatetime/tst_bench_qdatetime.cpp b/tests/benchmarks/corelib/time/qdatetime/tst_bench_qdatetime.cpp new file mode 100644 index 0000000000..302cf80abf --- /dev/null +++ b/tests/benchmarks/corelib/time/qdatetime/tst_bench_qdatetime.cpp @@ -0,0 +1,574 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module 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 + +class tst_QDateTime : public QObject +{ + Q_OBJECT + + enum : qint64 + { + SECS_PER_DAY = 86400, + MSECS_PER_DAY = 86400000, + JULIAN_DAY_1950 = 2433283, + JULIAN_DAY_1960 = 2436935, + JULIAN_DAY_1970 = 2440588, // Epoch + JULIAN_DAY_2010 = 2455198, + JULIAN_DAY_2011 = 2455563, + JULIAN_DAY_2020 = 2458850, + JULIAN_DAY_2050 = 2469808, + JULIAN_DAY_2060 = 2473460 + }; + + static QList daily(qint64 start, qint64 end); + static QList norse(qint64 start, qint64 end); + +private Q_SLOTS: + void create(); + void isNull(); + void isValid(); + void date(); + void time(); + void timeSpec(); + void offsetFromUtc(); + void timeZoneAbbreviation(); + void toMSecsSinceEpoch(); + void toMSecsSinceEpoch1950(); + void toMSecsSinceEpoch2050(); + void toMSecsSinceEpochTz(); + void toMSecsSinceEpoch1950Tz(); + void toMSecsSinceEpoch2050Tz(); + void setDate(); + void setTime(); + void setTimeSpec(); + void setOffsetFromUtc(); + void setMSecsSinceEpoch(); + void setMSecsSinceEpochTz(); + void toString(); + void toStringTextFormat(); + void toStringIsoFormat(); + void addDays(); + void addDaysTz(); + void addMSecs(); + void addMSecsTz(); + void toTimeSpec(); + void toOffsetFromUtc(); + void daysTo(); + void msecsTo(); + void equivalent(); + void equivalentUtc(); + void lessThan(); + void lessThanUtc(); + void currentDateTime(); + void currentDate(); + void currentTime(); + void currentDateTimeUtc(); + void currentMSecsSinceEpoch(); + void fromString(); + void fromStringText(); + void fromStringIso(); + void fromMSecsSinceEpoch(); + void fromMSecsSinceEpochUtc(); + void fromMSecsSinceEpochTz(); +}; + +QList tst_QDateTime::daily(qint64 start, qint64 end) +{ + QList list; + list.reserve(end - start); + for (int jd = start; jd < end; ++jd) + list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + return list; +} + +QList tst_QDateTime::norse(qint64 start, qint64 end) +{ + const QTimeZone cet("Europe/Oslo"); + QList list; + list.reserve(end - start); + for (int jd = start; jd < end; ++jd) + list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet)); + return list; +} + +void tst_QDateTime::create() +{ + QBENCHMARK { + for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) { + QDateTime test(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)); + Q_UNUSED(test); + } + } +} + +void tst_QDateTime::isNull() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDateTime &test : list) + test.isNull(); + } +} + +void tst_QDateTime::isValid() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDateTime &test : list) + test.isValid(); + } +} + +void tst_QDateTime::date() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDateTime &test : list) + test.date(); + } +} + +void tst_QDateTime::time() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDateTime &test : list) + test.time(); + } +} + +void tst_QDateTime::timeSpec() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDateTime &test : list) + test.timeSpec(); + } +} + +void tst_QDateTime::offsetFromUtc() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDateTime &test : list) + test.offsetFromUtc(); + } +} + +void tst_QDateTime::timeZoneAbbreviation() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDateTime &test : list) + test.timeZoneAbbreviation(); + } +} + +void tst_QDateTime::toMSecsSinceEpoch() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDateTime &test : list) + test.toMSecsSinceEpoch(); + } +} + +void tst_QDateTime::toMSecsSinceEpoch1950() +{ + const auto list = daily(JULIAN_DAY_1950, JULIAN_DAY_1960); + QBENCHMARK { + for (const QDateTime &test : list) + test.toMSecsSinceEpoch(); + } +} + +void tst_QDateTime::toMSecsSinceEpoch2050() +{ + const auto list = daily(JULIAN_DAY_2050, JULIAN_DAY_2060); + QBENCHMARK { + for (const QDateTime &test : list) + test.toMSecsSinceEpoch(); + } +} + +void tst_QDateTime::toMSecsSinceEpochTz() +{ + qint64 result; + const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDateTime &test : list) + result = test.toMSecsSinceEpoch(); + } + Q_UNUSED(result); +} + +void tst_QDateTime::toMSecsSinceEpoch1950Tz() +{ + qint64 result; + const auto list = norse(JULIAN_DAY_1950, JULIAN_DAY_1960); + QBENCHMARK { + for (const QDateTime &test : list) + result = test.toMSecsSinceEpoch(); + } + Q_UNUSED(result); +} + +void tst_QDateTime::toMSecsSinceEpoch2050Tz() +{ + qint64 result; + const auto list = norse(JULIAN_DAY_2050, JULIAN_DAY_2060); + QBENCHMARK { + for (const QDateTime &test : list) + result = test.toMSecsSinceEpoch(); + } + Q_UNUSED(result); +} + +void tst_QDateTime::setDate() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (QDateTime test : list) + test.setDate(QDate::fromJulianDay(JULIAN_DAY_2010)); + } +} + +void tst_QDateTime::setTime() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (QDateTime test : list) + test.setTime(QTime(12, 0, 0)); + } +} + +void tst_QDateTime::setTimeSpec() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (QDateTime test : list) + test.setTimeSpec(Qt::UTC); + } +} + +void tst_QDateTime::setOffsetFromUtc() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (QDateTime test : list) + test.setOffsetFromUtc(3600); + } +} + +void tst_QDateTime::setMSecsSinceEpoch() +{ + qint64 msecs = qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970 + 180) * MSECS_PER_DAY; + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (QDateTime test : list) + test.setMSecsSinceEpoch(msecs); + } +} + +void tst_QDateTime::setMSecsSinceEpochTz() +{ + const qint64 msecs = qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970 + 180) * MSECS_PER_DAY; + const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (QDateTime test : list) + test.setMSecsSinceEpoch(msecs); + } +} + +void tst_QDateTime::toString() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2011); + QBENCHMARK { + for (const QDateTime &test : list) + test.toString(QStringLiteral("yyy-MM-dd hh:mm:ss.zzz t")); + } +} + +void tst_QDateTime::toStringTextFormat() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2011); + QBENCHMARK { + for (const QDateTime &test : list) + test.toString(Qt::TextDate); + } +} + +void tst_QDateTime::toStringIsoFormat() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2011); + QBENCHMARK { + for (const QDateTime &test : list) + test.toString(Qt::ISODate); + } +} + +void tst_QDateTime::addDays() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QDateTime next; + QBENCHMARK { + for (const QDateTime &test : list) + next = test.addDays(1); + } + Q_UNUSED(next); +} + +void tst_QDateTime::addDaysTz() +{ + const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDateTime &test : list) + QDateTime result = test.addDays(1); + } +} + +void tst_QDateTime::addMSecs() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QDateTime next; + QBENCHMARK { + for (const QDateTime &test : list) + next = test.addMSecs(1); + } + Q_UNUSED(next); +} + +void tst_QDateTime::addMSecsTz() +{ + const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDateTime &test : list) + QDateTime result = test.addMSecs(1); + } +} + +void tst_QDateTime::toTimeSpec() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDateTime &test : list) + test.toTimeSpec(Qt::UTC); + } +} + +void tst_QDateTime::toOffsetFromUtc() +{ + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDateTime &test : list) + test.toOffsetFromUtc(3600); + } +} + +void tst_QDateTime::daysTo() +{ + const QDateTime other = QDateTime::fromMSecsSinceEpoch( + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDateTime &test : list) + test.daysTo(other); + } +} + +void tst_QDateTime::msecsTo() +{ + const QDateTime other = QDateTime::fromMSecsSinceEpoch( + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDateTime &test : list) + test.msecsTo(other); + } +} + +void tst_QDateTime::equivalent() +{ + bool result; + const QDateTime other = QDateTime::fromMSecsSinceEpoch( + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDateTime &test : list) + result = (test == other); + } + Q_UNUSED(result); +} + +void tst_QDateTime::equivalentUtc() +{ + bool result = false; + const QDateTime other = QDateTime::fromMSecsSinceEpoch( + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, Qt::UTC); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDateTime &test : list) + result = (test == other); + } + Q_UNUSED(result); +} + +void tst_QDateTime::lessThan() +{ + bool result = false; + const QDateTime other = QDateTime::fromMSecsSinceEpoch( + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDateTime &test : list) + result = (test < other); + } + Q_UNUSED(result); +} + +void tst_QDateTime::lessThanUtc() +{ + bool result = false; + const QDateTime other = QDateTime::fromMSecsSinceEpoch( + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, Qt::UTC); + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); + QBENCHMARK { + for (const QDateTime &test : list) + result = (test < other); + } + Q_UNUSED(result); +} + +void tst_QDateTime::currentDateTime() +{ + QBENCHMARK { + for (int i = 0; i < 1000; ++i) + QDateTime::currentDateTime(); + } +} + +void tst_QDateTime::currentDate() +{ + QBENCHMARK { + for (int i = 0; i < 1000; ++i) + QDate::currentDate(); + } +} + +void tst_QDateTime::currentTime() +{ + QBENCHMARK { + for (int i = 0; i < 1000; ++i) + QTime::currentTime(); + } +} + +void tst_QDateTime::currentDateTimeUtc() +{ + QBENCHMARK { + for (int i = 0; i < 1000; ++i) + QDateTime::currentDateTimeUtc(); + } +} + +void tst_QDateTime::currentMSecsSinceEpoch() +{ + QBENCHMARK { + for (int i = 0; i < 1000; ++i) + QDateTime::currentMSecsSinceEpoch(); + } +} + +void tst_QDateTime::fromString() +{ + QString format = "yyyy-MM-dd hh:mm:ss.zzz"; + QString input = "2010-01-01 13:12:11.999"; + QVERIFY(QDateTime::fromString(input, format).isValid()); + QBENCHMARK { + for (int i = 0; i < 1000; ++i) + QDateTime::fromString(input, format); + } +} + +void tst_QDateTime::fromStringText() +{ + QString input = "Wed Jan 2 01:02:03.000 2013 GMT"; + QBENCHMARK { + for (int i = 0; i < 1000; ++i) + QDateTime::fromString(input, Qt::TextDate); + } +} + +void tst_QDateTime::fromStringIso() +{ + QString input = "2010-01-01T13:28:34.999Z"; + QBENCHMARK { + for (int i = 0; i < 1000; ++i) + QDateTime::fromString(input, Qt::ISODate); + } +} + +void tst_QDateTime::fromMSecsSinceEpoch() +{ + const int start = JULIAN_DAY_2010 - JULIAN_DAY_1970; + const int end = JULIAN_DAY_2020 - JULIAN_DAY_1970; + QBENCHMARK { + for (int jd = start; jd < end; ++jd) + QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, Qt::LocalTime); + } +} + +void tst_QDateTime::fromMSecsSinceEpochUtc() +{ + const int start = JULIAN_DAY_2010 - JULIAN_DAY_1970; + const int end = JULIAN_DAY_2020 - JULIAN_DAY_1970; + QBENCHMARK { + for (int jd = start; jd < end; ++jd) + QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, Qt::UTC); + } +} + +void tst_QDateTime::fromMSecsSinceEpochTz() +{ + const int start = JULIAN_DAY_2010 - JULIAN_DAY_1970; + const int end = JULIAN_DAY_2020 - JULIAN_DAY_1970; + const QTimeZone cet("Europe/Oslo"); + QBENCHMARK { + for (int jd = start; jd < end; ++jd) + QDateTime test = QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, cet); + } +} + +QTEST_MAIN(tst_QDateTime) + +#include "tst_bench_qdatetime.moc" diff --git a/tests/benchmarks/corelib/time/qtimezone/CMakeLists.txt b/tests/benchmarks/corelib/time/qtimezone/CMakeLists.txt index c6487499af..99d8b7f044 100644 --- a/tests/benchmarks/corelib/time/qtimezone/CMakeLists.txt +++ b/tests/benchmarks/corelib/time/qtimezone/CMakeLists.txt @@ -1,12 +1,10 @@ -# Generated from qtimezone.pro. - ##################################################################### ## tst_bench_qtimezone Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qtimezone SOURCES - main.cpp + tst_bench_qtimezone.cpp PUBLIC_LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/time/qtimezone/main.cpp b/tests/benchmarks/corelib/time/qtimezone/main.cpp deleted file mode 100644 index 509d62d3bb..0000000000 --- a/tests/benchmarks/corelib/time/qtimezone/main.cpp +++ /dev/null @@ -1,166 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2019 Crimson AS -** Copyright (C) 2018 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module 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 - -// Enable to test *every* zone, rather than a hand-picked few, in some _data() sets: -// #define EXHAUSTIVE - -class tst_QTimeZone : public QObject -{ - Q_OBJECT - -private Q_SLOTS: - void isTimeZoneIdAvailable(); - void systemTimeZone(); - void zoneByName_data(); - void zoneByName(); - void transitionList_data(); - void transitionList(); - void transitionsForward_data() { transitionList_data(); } - void transitionsForward(); - void transitionsReverse_data() { transitionList_data(); } - void transitionsReverse(); -}; - -static QList enoughZones() -{ -#ifdef EXHAUSTIVE - auto available = QTimeZone::availableTimeZoneIds(); - QList result; - result.reserve(available.size() + 1); - for (conat auto &name : available) - result << name; -#else - QList result { QByteArray("UTC"), - // Those named overtly in tst_QDateTime: - QByteArray("Europe/Oslo"), QByteArray("America/Vancouver"), - QByteArray("Europe/Berlin"), QByteArray("America/Sao_Paulo"), - QByteArray("Pacific/Auckland"), QByteArray("Australia/Eucla"), - QByteArray("Asia/Kathmandu"), QByteArray("Pacific/Kiritimati"), - QByteArray("Pacific/Apia"), QByteArray("UTC+12:00"), - QByteArray("Australia/Sydney"), QByteArray("Asia/Singapore"), - QByteArray("Australia/Brisbane") }; -#endif - result << QByteArray("Vulcan/ShiKahr"); // invalid: also worth testing - return result; -} - -void tst_QTimeZone::isTimeZoneIdAvailable() -{ - const QList available = QTimeZone::availableTimeZoneIds(); - QBENCHMARK { - for (const QByteArray &id : available) - QVERIFY(QTimeZone::isTimeZoneIdAvailable(id)); - } -} - -void tst_QTimeZone::systemTimeZone() -{ - QBENCHMARK { - QTimeZone::systemTimeZone(); - } -} - -void tst_QTimeZone::zoneByName_data() -{ - QTest::addColumn("name"); - - const auto names = enoughZones(); - for (const auto &name : names) - QTest::newRow(name.constData()) << name; -} - -void tst_QTimeZone::zoneByName() -{ - QFETCH(QByteArray, name); - QTimeZone zone; - QBENCHMARK { - zone = QTimeZone(name); - } - Q_UNUSED(zone); -} - -void tst_QTimeZone::transitionList_data() -{ - QTest::addColumn("name"); - QTest::newRow("system") << QByteArray(); // Handled specially in the test. - - const auto names = enoughZones(); - for (const auto &name : names) { - QTimeZone zone(name); - if (zone.isValid() && zone.hasTransitions()) - QTest::newRow(name.constData()) << name; - } -} - -void tst_QTimeZone::transitionList() -{ - QFETCH(QByteArray, name); - const QTimeZone zone = name.isEmpty() ? QTimeZone::systemTimeZone() : QTimeZone(name); - const QDateTime early = QDate(1625, 6, 8).startOfDay(Qt::UTC); // Cassini's birth date - const QDateTime late // End of 32-bit signed time_t - = QDateTime::fromSecsSinceEpoch(std::numeric_limits::max(), Qt::UTC); - QTimeZone::OffsetDataList seq; - QBENCHMARK { - seq = zone.transitions(early, late); - } - Q_UNUSED(seq); -} - -void tst_QTimeZone::transitionsForward() -{ - QFETCH(QByteArray, name); - const QTimeZone zone = name.isEmpty() ? QTimeZone::systemTimeZone() : QTimeZone(name); - const QDateTime early = QDate(1625, 6, 8).startOfDay(Qt::UTC); // Cassini's birth date - QBENCHMARK { - QTimeZone::OffsetData tran = zone.nextTransition(early); - while (tran.atUtc.isValid()) - tran = zone.nextTransition(tran.atUtc); - } -} - -void tst_QTimeZone::transitionsReverse() -{ - QFETCH(QByteArray, name); - const QTimeZone zone = name.isEmpty() ? QTimeZone::systemTimeZone() : QTimeZone(name); - const QDateTime late // End of 32-bit signed time_t - = QDateTime::fromSecsSinceEpoch(std::numeric_limits::max(), Qt::UTC); - QBENCHMARK { - QTimeZone::OffsetData tran = zone.previousTransition(late); - while (tran.atUtc.isValid()) - tran = zone.previousTransition(tran.atUtc); - } -} - -QTEST_MAIN(tst_QTimeZone) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/time/qtimezone/tst_bench_qtimezone.cpp b/tests/benchmarks/corelib/time/qtimezone/tst_bench_qtimezone.cpp new file mode 100644 index 0000000000..36bb1dd24f --- /dev/null +++ b/tests/benchmarks/corelib/time/qtimezone/tst_bench_qtimezone.cpp @@ -0,0 +1,166 @@ +/**************************************************************************** +** +** Copyright (C) 2019 Crimson AS +** Copyright (C) 2018 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module 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 + +// Enable to test *every* zone, rather than a hand-picked few, in some _data() sets: +// #define EXHAUSTIVE + +class tst_QTimeZone : public QObject +{ + Q_OBJECT + +private Q_SLOTS: + void isTimeZoneIdAvailable(); + void systemTimeZone(); + void zoneByName_data(); + void zoneByName(); + void transitionList_data(); + void transitionList(); + void transitionsForward_data() { transitionList_data(); } + void transitionsForward(); + void transitionsReverse_data() { transitionList_data(); } + void transitionsReverse(); +}; + +static QList enoughZones() +{ +#ifdef EXHAUSTIVE + auto available = QTimeZone::availableTimeZoneIds(); + QList result; + result.reserve(available.size() + 1); + for (conat auto &name : available) + result << name; +#else + QList result { QByteArray("UTC"), + // Those named overtly in tst_QDateTime: + QByteArray("Europe/Oslo"), QByteArray("America/Vancouver"), + QByteArray("Europe/Berlin"), QByteArray("America/Sao_Paulo"), + QByteArray("Pacific/Auckland"), QByteArray("Australia/Eucla"), + QByteArray("Asia/Kathmandu"), QByteArray("Pacific/Kiritimati"), + QByteArray("Pacific/Apia"), QByteArray("UTC+12:00"), + QByteArray("Australia/Sydney"), QByteArray("Asia/Singapore"), + QByteArray("Australia/Brisbane") }; +#endif + result << QByteArray("Vulcan/ShiKahr"); // invalid: also worth testing + return result; +} + +void tst_QTimeZone::isTimeZoneIdAvailable() +{ + const QList available = QTimeZone::availableTimeZoneIds(); + QBENCHMARK { + for (const QByteArray &id : available) + QVERIFY(QTimeZone::isTimeZoneIdAvailable(id)); + } +} + +void tst_QTimeZone::systemTimeZone() +{ + QBENCHMARK { + QTimeZone::systemTimeZone(); + } +} + +void tst_QTimeZone::zoneByName_data() +{ + QTest::addColumn("name"); + + const auto names = enoughZones(); + for (const auto &name : names) + QTest::newRow(name.constData()) << name; +} + +void tst_QTimeZone::zoneByName() +{ + QFETCH(QByteArray, name); + QTimeZone zone; + QBENCHMARK { + zone = QTimeZone(name); + } + Q_UNUSED(zone); +} + +void tst_QTimeZone::transitionList_data() +{ + QTest::addColumn("name"); + QTest::newRow("system") << QByteArray(); // Handled specially in the test. + + const auto names = enoughZones(); + for (const auto &name : names) { + QTimeZone zone(name); + if (zone.isValid() && zone.hasTransitions()) + QTest::newRow(name.constData()) << name; + } +} + +void tst_QTimeZone::transitionList() +{ + QFETCH(QByteArray, name); + const QTimeZone zone = name.isEmpty() ? QTimeZone::systemTimeZone() : QTimeZone(name); + const QDateTime early = QDate(1625, 6, 8).startOfDay(Qt::UTC); // Cassini's birth date + const QDateTime late // End of 32-bit signed time_t + = QDateTime::fromSecsSinceEpoch(std::numeric_limits::max(), Qt::UTC); + QTimeZone::OffsetDataList seq; + QBENCHMARK { + seq = zone.transitions(early, late); + } + Q_UNUSED(seq); +} + +void tst_QTimeZone::transitionsForward() +{ + QFETCH(QByteArray, name); + const QTimeZone zone = name.isEmpty() ? QTimeZone::systemTimeZone() : QTimeZone(name); + const QDateTime early = QDate(1625, 6, 8).startOfDay(Qt::UTC); // Cassini's birth date + QBENCHMARK { + QTimeZone::OffsetData tran = zone.nextTransition(early); + while (tran.atUtc.isValid()) + tran = zone.nextTransition(tran.atUtc); + } +} + +void tst_QTimeZone::transitionsReverse() +{ + QFETCH(QByteArray, name); + const QTimeZone zone = name.isEmpty() ? QTimeZone::systemTimeZone() : QTimeZone(name); + const QDateTime late // End of 32-bit signed time_t + = QDateTime::fromSecsSinceEpoch(std::numeric_limits::max(), Qt::UTC); + QBENCHMARK { + QTimeZone::OffsetData tran = zone.previousTransition(late); + while (tran.atUtc.isValid()) + tran = zone.previousTransition(tran.atUtc); + } +} + +QTEST_MAIN(tst_QTimeZone) + +#include "tst_bench_qtimezone.moc" diff --git a/tests/benchmarks/corelib/tools/CMakeLists.txt b/tests/benchmarks/corelib/tools/CMakeLists.txt index 805aa92229..25cc02ad1d 100644 --- a/tests/benchmarks/corelib/tools/CMakeLists.txt +++ b/tests/benchmarks/corelib/tools/CMakeLists.txt @@ -1,13 +1,13 @@ -# Generated from tools.pro. - add_subdirectory(containers-associative) add_subdirectory(containers-sequential) add_subdirectory(qcontiguouscache) add_subdirectory(qcryptographichash) +add_subdirectory(qhash) add_subdirectory(qlist) add_subdirectory(qmap) add_subdirectory(qrect) add_subdirectory(qringbuffer) +add_subdirectory(qset) add_subdirectory(qsharedpointer) add_subdirectory(qstack) add_subdirectory(qvector) diff --git a/tests/benchmarks/corelib/tools/containers-associative/CMakeLists.txt b/tests/benchmarks/corelib/tools/containers-associative/CMakeLists.txt index 1e653fa98d..50bf8a0c0f 100644 --- a/tests/benchmarks/corelib/tools/containers-associative/CMakeLists.txt +++ b/tests/benchmarks/corelib/tools/containers-associative/CMakeLists.txt @@ -1,15 +1,10 @@ -# Generated from containers-associative.pro. - ##################################################################### -## tst_bench_containers-associative Binary: +## tst_bench_containers_associative Binary: ##################################################################### -qt_internal_add_benchmark(tst_bench_containers-associative +qt_internal_add_benchmark(tst_bench_containers_associative SOURCES - main.cpp + tst_bench_containers_associative.cpp PUBLIC_LIBRARIES Qt::Test ) - -#### Keys ignored in scope 1:.:.:containers-associative.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/tools/containers-associative/main.cpp b/tests/benchmarks/corelib/tools/containers-associative/main.cpp deleted file mode 100644 index 555d4bf843..0000000000 --- a/tests/benchmarks/corelib/tools/containers-associative/main.cpp +++ /dev/null @@ -1,130 +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_associative_containers : public QObject -{ - Q_OBJECT -private slots: - void insert_data(); - void insert(); - void lookup_data(); - void lookup(); -}; - -template -void testInsert(int size) -{ - T container; - - QBENCHMARK { - for (int i = 0; i < size; ++i) - container.insert(i, i); - } -} - -void tst_associative_containers::insert_data() -{ - QTest::addColumn("useHash"); - QTest::addColumn("size"); - - for (int size = 10; size < 20000; size += 100) { - - const QByteArray sizeString = QByteArray::number(size); - - QTest::newRow(QByteArray("hash--" + sizeString).constData()) << true << size; - QTest::newRow(QByteArray("map--" + sizeString).constData()) << false << size; - } -} - -void tst_associative_containers::insert() -{ - QFETCH(bool, useHash); - QFETCH(int, size); - - QHash testHash; - QMap testMap; - - if (useHash) { - testInsert >(size); - } else { - testInsert >(size); - } -} - -void tst_associative_containers::lookup_data() -{ -// setReportType(LineChartReport); -// setChartTitle("Time to call value(), with an increasing number of items in the container"); - - QTest::addColumn("useHash"); - QTest::addColumn("size"); - - for (int size = 10; size < 20000; size += 100) { - - const QByteArray sizeString = QByteArray::number(size); - - QTest::newRow(QByteArray("hash--" + sizeString).constData()) << true << size; - QTest::newRow(QByteArray("map--" + sizeString).constData()) << false << size; - } -} - -template -void testLookup(int size) -{ - T container; - - for (int i = 0; i < size; ++i) - container.insert(i, i); - - int val; - - QBENCHMARK { - for (int i = 0; i < size; ++i) - val = container.value(i); - - } - Q_UNUSED(val); -} - -void tst_associative_containers::lookup() -{ - QFETCH(bool, useHash); - QFETCH(int, size); - - if (useHash) { - testLookup >(size); - } else { - testLookup >(size); - } -} - -QTEST_MAIN(tst_associative_containers) -#include "main.moc" diff --git a/tests/benchmarks/corelib/tools/containers-associative/tst_bench_containers_associative.cpp b/tests/benchmarks/corelib/tools/containers-associative/tst_bench_containers_associative.cpp new file mode 100644 index 0000000000..6bab99cad7 --- /dev/null +++ b/tests/benchmarks/corelib/tools/containers-associative/tst_bench_containers_associative.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** 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_associative_containers : public QObject +{ + Q_OBJECT +private slots: + void insert_data(); + void insert(); + void lookup_data(); + void lookup(); +}; + +template +void testInsert(int size) +{ + T container; + + QBENCHMARK { + for (int i = 0; i < size; ++i) + container.insert(i, i); + } +} + +void tst_associative_containers::insert_data() +{ + QTest::addColumn("useHash"); + QTest::addColumn("size"); + + for (int size = 10; size < 20000; size += 100) { + + const QByteArray sizeString = QByteArray::number(size); + + QTest::newRow(QByteArray("hash--" + sizeString).constData()) << true << size; + QTest::newRow(QByteArray("map--" + sizeString).constData()) << false << size; + } +} + +void tst_associative_containers::insert() +{ + QFETCH(bool, useHash); + QFETCH(int, size); + + QHash testHash; + QMap testMap; + + if (useHash) { + testInsert >(size); + } else { + testInsert >(size); + } +} + +void tst_associative_containers::lookup_data() +{ +// setReportType(LineChartReport); +// setChartTitle("Time to call value(), with an increasing number of items in the container"); + + QTest::addColumn("useHash"); + QTest::addColumn("size"); + + for (int size = 10; size < 20000; size += 100) { + + const QByteArray sizeString = QByteArray::number(size); + + QTest::newRow(QByteArray("hash--" + sizeString).constData()) << true << size; + QTest::newRow(QByteArray("map--" + sizeString).constData()) << false << size; + } +} + +template +void testLookup(int size) +{ + T container; + + for (int i = 0; i < size; ++i) + container.insert(i, i); + + int val; + + QBENCHMARK { + for (int i = 0; i < size; ++i) + val = container.value(i); + + } + Q_UNUSED(val); +} + +void tst_associative_containers::lookup() +{ + QFETCH(bool, useHash); + QFETCH(int, size); + + if (useHash) { + testLookup >(size); + } else { + testLookup >(size); + } +} + +QTEST_MAIN(tst_associative_containers) + +#include "tst_bench_containers_associative.moc" diff --git a/tests/benchmarks/corelib/tools/containers-sequential/CMakeLists.txt b/tests/benchmarks/corelib/tools/containers-sequential/CMakeLists.txt index f8ebc69c29..2e6d26e343 100644 --- a/tests/benchmarks/corelib/tools/containers-sequential/CMakeLists.txt +++ b/tests/benchmarks/corelib/tools/containers-sequential/CMakeLists.txt @@ -1,15 +1,10 @@ -# Generated from containers-sequential.pro. - ##################################################################### ## tst_bench_containers-sequential Binary: ##################################################################### -qt_internal_add_benchmark(tst_bench_containers-sequential +qt_internal_add_benchmark(tst_bench_containers_sequential SOURCES - main.cpp + tst_bench_containers_sequential.cpp PUBLIC_LIBRARIES Qt::Test ) - -#### Keys ignored in scope 1:.:.:containers-sequential.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/tools/containers-sequential/main.cpp b/tests/benchmarks/corelib/tools/containers-sequential/main.cpp deleted file mode 100644 index 1bb1a02a24..0000000000 --- a/tests/benchmarks/corelib/tools/containers-sequential/main.cpp +++ /dev/null @@ -1,247 +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$ -** -****************************************************************************/ -// This file contains benchmarks for comparing QList against std::vector - -#include -#include -#include - -#include - -template // T is the item type -class UseCases { -public: - virtual ~UseCases() {} - - // Use case: Insert \a size items into the vector. - virtual void insert(int size) = 0; - - // Use case: Lookup \a size items from the vector. - virtual void lookup(int size) = 0; -}; - -template -T * f(T *ts) // dummy function to prevent code from being optimized away by the compiler -{ - return ts; -} - -// This subclass implements the use cases using QList as efficiently as possible. -template -class UseCases_QList : public UseCases -{ - void insert(int size) override - { - QList v; - T t{}; - QBENCHMARK { - for (int i = 0; i < size; ++i) - v.append(t); - } - } - - void lookup(int size) override - { - QList v; - - T t{}; - for (int i = 0; i < size; ++i) - v.append(t); - - T *ts = new T[size]; - QBENCHMARK { - for (int i = 0; i < size; ++i) - ts[i] = v.value(i); - } - f(ts); - delete[] ts; - } -}; - -// This subclass implements the use cases using std::vector as efficiently as possible. -template -class UseCases_stdvector : public UseCases -{ - void insert(int size) override - { - std::vector v; - T t; - QBENCHMARK { - for (int i = 0; i < size; ++i) - v.push_back(t); - } - } - - void lookup(int size) override - { - std::vector v; - - T t; - for (int i = 0; i < size; ++i) - v.push_back(t); - - T *ts = new T[size]; - QBENCHMARK { - for (int i = 0; i < size; ++i) - ts[i] = v[i]; - } - f(ts); - delete[] ts; - } -}; - -struct Large { // A "large" item type - int x[1000]; -}; - -#define LARGE_MAX_SIZE 20000 - -class tst_vector_vs_std : public QObject -{ - Q_OBJECT -public: - tst_vector_vs_std() - { - useCases_QList_int = new UseCases_QList; - useCases_stdvector_int = new UseCases_stdvector; - - useCases_QList_Large = new UseCases_QList; - useCases_stdvector_Large = new UseCases_stdvector; - } - -private: - UseCases *useCases_QList_int; - UseCases *useCases_stdvector_int; - UseCases *useCases_QList_Large; - UseCases *useCases_stdvector_Large; - -private slots: - void insert_int_data(); - void insert_int(); - void insert_Large_data(); - void insert_Large(); - void lookup_int_data(); - void lookup_int(); - void lookup_Large_data(); - void lookup_Large(); -}; - -void tst_vector_vs_std::insert_int_data() -{ - QTest::addColumn("useStd"); - QTest::addColumn("size"); - - for (int size = 10; size < 20000; size += 100) { - const QByteArray sizeString = QByteArray::number(size); - QTest::newRow(QByteArray("std::vector-int--" + sizeString).constData()) << true << size; - QTest::newRow(QByteArray("QList-int--" + sizeString).constData()) << false << size; - } -} - -void tst_vector_vs_std::insert_int() -{ - QFETCH(bool, useStd); - QFETCH(int, size); - - if (useStd) - useCases_stdvector_int->insert(size); - else - useCases_QList_int->insert(size); -} - -void tst_vector_vs_std::insert_Large_data() -{ - QTest::addColumn("useStd"); - QTest::addColumn("size"); - - for (int size = 10; size < LARGE_MAX_SIZE; size += 100) { - const QByteArray sizeString = QByteArray::number(size); - QTest::newRow(QByteArray("std::vector-Large--" + sizeString).constData()) << true << size; - QTest::newRow(QByteArray("QList-Large--" + sizeString).constData()) << false << size; - } -} - -void tst_vector_vs_std::insert_Large() -{ - QFETCH(bool, useStd); - QFETCH(int, size); - - if (useStd) - useCases_stdvector_Large->insert(size); - else - useCases_QList_Large->insert(size); -} - -void tst_vector_vs_std::lookup_int_data() -{ - QTest::addColumn("useStd"); - QTest::addColumn("size"); - - for (int size = 10; size < 20000; size += 100) { - const QByteArray sizeString = QByteArray::number(size); - QTest::newRow(QByteArray("std::vector-int--" + sizeString).constData()) << true << size; - QTest::newRow(QByteArray("QList-int--" + sizeString).constData()) << false << size; - } -} - -void tst_vector_vs_std::lookup_int() -{ - QFETCH(bool, useStd); - QFETCH(int, size); - - if (useStd) - useCases_stdvector_int->lookup(size); - else - useCases_QList_int->lookup(size); -} - -void tst_vector_vs_std::lookup_Large_data() -{ - QTest::addColumn("useStd"); - QTest::addColumn("size"); - - for (int size = 10; size < LARGE_MAX_SIZE; size += 100) { - const QByteArray sizeString = QByteArray::number(size); - QTest::newRow(QByteArray("std::vector-Large--" + sizeString).constData()) << true << size; - QTest::newRow(QByteArray("QList-Large--" + sizeString).constData()) << false << size; - } -} - -void tst_vector_vs_std::lookup_Large() -{ - QFETCH(bool, useStd); - QFETCH(int, size); - - if (useStd) - useCases_stdvector_Large->lookup(size); - else - useCases_QList_Large->lookup(size); -} - -QTEST_MAIN(tst_vector_vs_std) -#include "main.moc" diff --git a/tests/benchmarks/corelib/tools/containers-sequential/tst_bench_containers_sequential.cpp b/tests/benchmarks/corelib/tools/containers-sequential/tst_bench_containers_sequential.cpp new file mode 100644 index 0000000000..55d4cc72df --- /dev/null +++ b/tests/benchmarks/corelib/tools/containers-sequential/tst_bench_containers_sequential.cpp @@ -0,0 +1,248 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +// This file contains benchmarks for comparing QList against std::vector + +#include +#include +#include + +#include + +template // T is the item type +class UseCases { +public: + virtual ~UseCases() {} + + // Use case: Insert \a size items into the vector. + virtual void insert(int size) = 0; + + // Use case: Lookup \a size items from the vector. + virtual void lookup(int size) = 0; +}; + +template +T * f(T *ts) // dummy function to prevent code from being optimized away by the compiler +{ + return ts; +} + +// This subclass implements the use cases using QList as efficiently as possible. +template +class UseCases_QList : public UseCases +{ + void insert(int size) override + { + QList v; + T t{}; + QBENCHMARK { + for (int i = 0; i < size; ++i) + v.append(t); + } + } + + void lookup(int size) override + { + QList v; + + T t{}; + for (int i = 0; i < size; ++i) + v.append(t); + + T *ts = new T[size]; + QBENCHMARK { + for (int i = 0; i < size; ++i) + ts[i] = v.value(i); + } + f(ts); + delete[] ts; + } +}; + +// This subclass implements the use cases using std::vector as efficiently as possible. +template +class UseCases_stdvector : public UseCases +{ + void insert(int size) override + { + std::vector v; + T t; + QBENCHMARK { + for (int i = 0; i < size; ++i) + v.push_back(t); + } + } + + void lookup(int size) override + { + std::vector v; + + T t; + for (int i = 0; i < size; ++i) + v.push_back(t); + + T *ts = new T[size]; + QBENCHMARK { + for (int i = 0; i < size; ++i) + ts[i] = v[i]; + } + f(ts); + delete[] ts; + } +}; + +struct Large { // A "large" item type + int x[1000]; +}; + +#define LARGE_MAX_SIZE 20000 + +class tst_vector_vs_std : public QObject +{ + Q_OBJECT +public: + tst_vector_vs_std() + { + useCases_QList_int = new UseCases_QList; + useCases_stdvector_int = new UseCases_stdvector; + + useCases_QList_Large = new UseCases_QList; + useCases_stdvector_Large = new UseCases_stdvector; + } + +private: + UseCases *useCases_QList_int; + UseCases *useCases_stdvector_int; + UseCases *useCases_QList_Large; + UseCases *useCases_stdvector_Large; + +private slots: + void insert_int_data(); + void insert_int(); + void insert_Large_data(); + void insert_Large(); + void lookup_int_data(); + void lookup_int(); + void lookup_Large_data(); + void lookup_Large(); +}; + +void tst_vector_vs_std::insert_int_data() +{ + QTest::addColumn("useStd"); + QTest::addColumn("size"); + + for (int size = 10; size < 20000; size += 100) { + const QByteArray sizeString = QByteArray::number(size); + QTest::newRow(QByteArray("std::vector-int--" + sizeString).constData()) << true << size; + QTest::newRow(QByteArray("QList-int--" + sizeString).constData()) << false << size; + } +} + +void tst_vector_vs_std::insert_int() +{ + QFETCH(bool, useStd); + QFETCH(int, size); + + if (useStd) + useCases_stdvector_int->insert(size); + else + useCases_QList_int->insert(size); +} + +void tst_vector_vs_std::insert_Large_data() +{ + QTest::addColumn("useStd"); + QTest::addColumn("size"); + + for (int size = 10; size < LARGE_MAX_SIZE; size += 100) { + const QByteArray sizeString = QByteArray::number(size); + QTest::newRow(QByteArray("std::vector-Large--" + sizeString).constData()) << true << size; + QTest::newRow(QByteArray("QList-Large--" + sizeString).constData()) << false << size; + } +} + +void tst_vector_vs_std::insert_Large() +{ + QFETCH(bool, useStd); + QFETCH(int, size); + + if (useStd) + useCases_stdvector_Large->insert(size); + else + useCases_QList_Large->insert(size); +} + +void tst_vector_vs_std::lookup_int_data() +{ + QTest::addColumn("useStd"); + QTest::addColumn("size"); + + for (int size = 10; size < 20000; size += 100) { + const QByteArray sizeString = QByteArray::number(size); + QTest::newRow(QByteArray("std::vector-int--" + sizeString).constData()) << true << size; + QTest::newRow(QByteArray("QList-int--" + sizeString).constData()) << false << size; + } +} + +void tst_vector_vs_std::lookup_int() +{ + QFETCH(bool, useStd); + QFETCH(int, size); + + if (useStd) + useCases_stdvector_int->lookup(size); + else + useCases_QList_int->lookup(size); +} + +void tst_vector_vs_std::lookup_Large_data() +{ + QTest::addColumn("useStd"); + QTest::addColumn("size"); + + for (int size = 10; size < LARGE_MAX_SIZE; size += 100) { + const QByteArray sizeString = QByteArray::number(size); + QTest::newRow(QByteArray("std::vector-Large--" + sizeString).constData()) << true << size; + QTest::newRow(QByteArray("QList-Large--" + sizeString).constData()) << false << size; + } +} + +void tst_vector_vs_std::lookup_Large() +{ + QFETCH(bool, useStd); + QFETCH(int, size); + + if (useStd) + useCases_stdvector_Large->lookup(size); + else + useCases_QList_Large->lookup(size); +} + +QTEST_MAIN(tst_vector_vs_std) + +#include "tst_bench_containers_sequential.moc" diff --git a/tests/benchmarks/corelib/tools/qcontiguouscache/CMakeLists.txt b/tests/benchmarks/corelib/tools/qcontiguouscache/CMakeLists.txt index e683d60de2..29366ecf36 100644 --- a/tests/benchmarks/corelib/tools/qcontiguouscache/CMakeLists.txt +++ b/tests/benchmarks/corelib/tools/qcontiguouscache/CMakeLists.txt @@ -1,12 +1,10 @@ -# Generated from qcontiguouscache.pro. - ##################################################################### ## tst_bench_qcontiguouscache Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qcontiguouscache SOURCES - main.cpp + tst_bench_qcontiguouscache.cpp PUBLIC_LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/tools/qcontiguouscache/main.cpp b/tests/benchmarks/corelib/tools/qcontiguouscache/main.cpp deleted file mode 100644 index 368c8b66bb..0000000000 --- a/tests/benchmarks/corelib/tools/qcontiguouscache/main.cpp +++ /dev/null @@ -1,179 +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 - -#include -#include - -class tst_QContiguousCache : public QObject -{ - Q_OBJECT -public: - tst_QContiguousCache() {} - virtual ~tst_QContiguousCache() {} -private slots: - void asScrollingList(); - void cacheBenchmark(); - void contiguousCacheBenchmark(); -}; - -QTEST_MAIN(tst_QContiguousCache) - -void tst_QContiguousCache::asScrollingList() -{ - int i; - QContiguousCache c(10); - - // Once allocated QContiguousCache should not - // allocate any additional memory for non - // complex data types. - QBENCHMARK { - // simulate scrolling in a list of items; - for (i = 0; i < 10; ++i) { - QCOMPARE(c.available(), 10-i); - c.append(i); - } - - QCOMPARE(c.firstIndex(), 0); - QCOMPARE(c.lastIndex(), 9); - QCOMPARE(c.first(), 0); - QCOMPARE(c.last(), 9); - QVERIFY(!c.containsIndex(-1)); - QVERIFY(!c.containsIndex(10)); - QCOMPARE(c.available(), 0); - - for (i = 0; i < 10; ++i) { - QVERIFY(c.containsIndex(i)); - QCOMPARE(c.at(i), i); - QCOMPARE(c[i], i); - QCOMPARE(((const QContiguousCache)c)[i], i); - } - - for (i = 10; i < 30; ++i) - c.append(i); - - QCOMPARE(c.firstIndex(), 20); - QCOMPARE(c.lastIndex(), 29); - QCOMPARE(c.first(), 20); - QCOMPARE(c.last(), 29); - QVERIFY(!c.containsIndex(19)); - QVERIFY(!c.containsIndex(30)); - QCOMPARE(c.available(), 0); - - for (i = 20; i < 30; ++i) { - QVERIFY(c.containsIndex(i)); - QCOMPARE(c.at(i), i); - QCOMPARE(c[i], i); - QCOMPARE(((const QContiguousCache )c)[i], i); - } - - for (i = 19; i >= 10; --i) - c.prepend(i); - - QCOMPARE(c.firstIndex(), 10); - QCOMPARE(c.lastIndex(), 19); - QCOMPARE(c.first(), 10); - QCOMPARE(c.last(), 19); - QVERIFY(!c.containsIndex(9)); - QVERIFY(!c.containsIndex(20)); - QCOMPARE(c.available(), 0); - - for (i = 10; i < 20; ++i) { - QVERIFY(c.containsIndex(i)); - QCOMPARE(c.at(i), i); - QCOMPARE(c[i], i); - QCOMPARE(((const QContiguousCache )c)[i], i); - } - - for (i = 200; i < 220; ++i) - c.insert(i, i); - - QCOMPARE(c.firstIndex(), 210); - QCOMPARE(c.lastIndex(), 219); - QCOMPARE(c.first(), 210); - QCOMPARE(c.last(), 219); - QVERIFY(!c.containsIndex(209)); - QVERIFY(!c.containsIndex(300)); - QCOMPARE(c.available(), 0); - - for (i = 210; i < 220; ++i) { - QVERIFY(c.containsIndex(i)); - QCOMPARE(c.at(i), i); - QCOMPARE(c[i], i); - QCOMPARE(((const QContiguousCache )c)[i], i); - } - c.clear(); // needed to reset benchmark - } - - // from a specific bug that was encountered. 100 to 299 cached, attempted to cache 250 - 205 via insert, failed. - // bug was that item at 150 would instead be item that should have been inserted at 250 - c.setCapacity(200); - for (i = 100; i < 300; ++i) - c.insert(i, i); - for (i = 250; i <= 306; ++i) - c.insert(i, 1000+i); - for (i = 107; i <= 306; ++i) { - QVERIFY(c.containsIndex(i)); - QCOMPARE(c.at(i), i < 250 ? i : 1000+i); - } -} - -/* - Benchmarks must be near identical in tasks to be fair. - QCache uses pointers to ints as its a requirement of QCache, - whereas QContiguousCache doesn't support pointers (won't free them). - Given the ability to use simple data types is a benefit, its - fair. Although this obviously must take into account we are - testing QContiguousCache use cases here, QCache has its own - areas where it is the more sensible class to use. -*/ -void tst_QContiguousCache::cacheBenchmark() -{ - QBENCHMARK { - QCache cache; - cache.setMaxCost(100); - - for (int i = 0; i < 1000; i++) - cache.insert(i, new int(i)); - } -} - -void tst_QContiguousCache::contiguousCacheBenchmark() -{ - QBENCHMARK { - QContiguousCache contiguousCache(100); - for (int i = 0; i < 1000; i++) - contiguousCache.insert(i, i); - } -} - -#include "main.moc" diff --git a/tests/benchmarks/corelib/tools/qcontiguouscache/tst_bench_qcontiguouscache.cpp b/tests/benchmarks/corelib/tools/qcontiguouscache/tst_bench_qcontiguouscache.cpp new file mode 100644 index 0000000000..bc235b6747 --- /dev/null +++ b/tests/benchmarks/corelib/tools/qcontiguouscache/tst_bench_qcontiguouscache.cpp @@ -0,0 +1,179 @@ +/**************************************************************************** +** +** 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 + +#include +#include + +class tst_QContiguousCache : public QObject +{ + Q_OBJECT +public: + tst_QContiguousCache() {} + virtual ~tst_QContiguousCache() {} +private slots: + void asScrollingList(); + void cacheBenchmark(); + void contiguousCacheBenchmark(); +}; + +void tst_QContiguousCache::asScrollingList() +{ + int i; + QContiguousCache c(10); + + // Once allocated QContiguousCache should not + // allocate any additional memory for non + // complex data types. + QBENCHMARK { + // simulate scrolling in a list of items; + for (i = 0; i < 10; ++i) { + QCOMPARE(c.available(), 10-i); + c.append(i); + } + + QCOMPARE(c.firstIndex(), 0); + QCOMPARE(c.lastIndex(), 9); + QCOMPARE(c.first(), 0); + QCOMPARE(c.last(), 9); + QVERIFY(!c.containsIndex(-1)); + QVERIFY(!c.containsIndex(10)); + QCOMPARE(c.available(), 0); + + for (i = 0; i < 10; ++i) { + QVERIFY(c.containsIndex(i)); + QCOMPARE(c.at(i), i); + QCOMPARE(c[i], i); + QCOMPARE(((const QContiguousCache)c)[i], i); + } + + for (i = 10; i < 30; ++i) + c.append(i); + + QCOMPARE(c.firstIndex(), 20); + QCOMPARE(c.lastIndex(), 29); + QCOMPARE(c.first(), 20); + QCOMPARE(c.last(), 29); + QVERIFY(!c.containsIndex(19)); + QVERIFY(!c.containsIndex(30)); + QCOMPARE(c.available(), 0); + + for (i = 20; i < 30; ++i) { + QVERIFY(c.containsIndex(i)); + QCOMPARE(c.at(i), i); + QCOMPARE(c[i], i); + QCOMPARE(((const QContiguousCache )c)[i], i); + } + + for (i = 19; i >= 10; --i) + c.prepend(i); + + QCOMPARE(c.firstIndex(), 10); + QCOMPARE(c.lastIndex(), 19); + QCOMPARE(c.first(), 10); + QCOMPARE(c.last(), 19); + QVERIFY(!c.containsIndex(9)); + QVERIFY(!c.containsIndex(20)); + QCOMPARE(c.available(), 0); + + for (i = 10; i < 20; ++i) { + QVERIFY(c.containsIndex(i)); + QCOMPARE(c.at(i), i); + QCOMPARE(c[i], i); + QCOMPARE(((const QContiguousCache )c)[i], i); + } + + for (i = 200; i < 220; ++i) + c.insert(i, i); + + QCOMPARE(c.firstIndex(), 210); + QCOMPARE(c.lastIndex(), 219); + QCOMPARE(c.first(), 210); + QCOMPARE(c.last(), 219); + QVERIFY(!c.containsIndex(209)); + QVERIFY(!c.containsIndex(300)); + QCOMPARE(c.available(), 0); + + for (i = 210; i < 220; ++i) { + QVERIFY(c.containsIndex(i)); + QCOMPARE(c.at(i), i); + QCOMPARE(c[i], i); + QCOMPARE(((const QContiguousCache )c)[i], i); + } + c.clear(); // needed to reset benchmark + } + + // from a specific bug that was encountered. 100 to 299 cached, attempted to cache 250 - 205 via insert, failed. + // bug was that item at 150 would instead be item that should have been inserted at 250 + c.setCapacity(200); + for (i = 100; i < 300; ++i) + c.insert(i, i); + for (i = 250; i <= 306; ++i) + c.insert(i, 1000+i); + for (i = 107; i <= 306; ++i) { + QVERIFY(c.containsIndex(i)); + QCOMPARE(c.at(i), i < 250 ? i : 1000+i); + } +} + +/* + Benchmarks must be near identical in tasks to be fair. + QCache uses pointers to ints as its a requirement of QCache, + whereas QContiguousCache doesn't support pointers (won't free them). + Given the ability to use simple data types is a benefit, its + fair. Although this obviously must take into account we are + testing QContiguousCache use cases here, QCache has its own + areas where it is the more sensible class to use. +*/ +void tst_QContiguousCache::cacheBenchmark() +{ + QBENCHMARK { + QCache cache; + cache.setMaxCost(100); + + for (int i = 0; i < 1000; i++) + cache.insert(i, new int(i)); + } +} + +void tst_QContiguousCache::contiguousCacheBenchmark() +{ + QBENCHMARK { + QContiguousCache contiguousCache(100); + for (int i = 0; i < 1000; i++) + contiguousCache.insert(i, i); + } +} + +QTEST_MAIN(tst_QContiguousCache) + +#include "tst_bench_qcontiguouscache.moc" diff --git a/tests/benchmarks/corelib/tools/qcryptographichash/CMakeLists.txt b/tests/benchmarks/corelib/tools/qcryptographichash/CMakeLists.txt index 2ca8e683e1..e9d539eb1a 100644 --- a/tests/benchmarks/corelib/tools/qcryptographichash/CMakeLists.txt +++ b/tests/benchmarks/corelib/tools/qcryptographichash/CMakeLists.txt @@ -1,12 +1,10 @@ -# Generated from qcryptographichash.pro. - ##################################################################### ## tst_bench_qcryptographichash Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qcryptographichash SOURCES - main.cpp + tst_bench_qcryptographichash.cpp PUBLIC_LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/tools/qcryptographichash/main.cpp b/tests/benchmarks/corelib/tools/qcryptographichash/main.cpp deleted file mode 100644 index 1f0a7373bb..0000000000 --- a/tests/benchmarks/corelib/tools/qcryptographichash/main.cpp +++ /dev/null @@ -1,188 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2017 Intel Corporation. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module 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_bench_QCryptographicHash : public QObject -{ - Q_OBJECT - QByteArray blockOfData; - -public: - tst_bench_QCryptographicHash(); - -private Q_SLOTS: - void hash_data(); - void hash(); - void addData_data() { hash_data(); } - void addData(); - void addDataChunked_data() { hash_data(); } - void addDataChunked(); -}; - -const int MaxCryptoAlgorithm = QCryptographicHash::Sha3_512; -const int MaxBlockSize = 65536; - -const char *algoname(int i) -{ - switch (QCryptographicHash::Algorithm(i)) { - case QCryptographicHash::Md4: - return "md4-"; - case QCryptographicHash::Md5: - return "md5-"; - case QCryptographicHash::Sha1: - return "sha1-"; - case QCryptographicHash::Sha224: - return "sha2_224-"; - case QCryptographicHash::Sha256: - return "sha2_256-"; - case QCryptographicHash::Sha384: - return "sha2_384-"; - case QCryptographicHash::Sha512: - return "sha2_512-"; - case QCryptographicHash::Sha3_224: - return "sha3_224-"; - case QCryptographicHash::Sha3_256: - return "sha3_256-"; - case QCryptographicHash::Sha3_384: - return "sha3_384-"; - case QCryptographicHash::Sha3_512: - return "sha3_512-"; - case QCryptographicHash::Keccak_224: - return "keccak_224-"; - case QCryptographicHash::Keccak_256: - return "keccak_256-"; - case QCryptographicHash::Keccak_384: - return "keccak_384-"; - case QCryptographicHash::Keccak_512: - return "keccak_512-"; - case QCryptographicHash::Blake2b_160: - return "blake2b_160-"; - case QCryptographicHash::Blake2b_256: - return "blake2b_256-"; - case QCryptographicHash::Blake2b_384: - return "blake2b_384-"; - case QCryptographicHash::Blake2b_512: - return "blake2b_512-"; - case QCryptographicHash::Blake2s_128: - return "blake2s_128-"; - case QCryptographicHash::Blake2s_160: - return "blake2s_160-"; - case QCryptographicHash::Blake2s_224: - return "blake2s_224-"; - case QCryptographicHash::Blake2s_256: - return "blake2s_256-"; - } - Q_UNREACHABLE(); - return nullptr; -} - -tst_bench_QCryptographicHash::tst_bench_QCryptographicHash() - : blockOfData(MaxBlockSize, Qt::Uninitialized) -{ -#ifdef Q_OS_UNIX - QFile urandom("/dev/urandom"); - if (urandom.open(QIODevice::ReadOnly | QIODevice::Unbuffered)) { - QCOMPARE(urandom.read(blockOfData.data(), blockOfData.size()), qint64(MaxBlockSize)); - } else -#endif - { - for (int i = 0; i < MaxBlockSize; ++i) - blockOfData[i] = QRandomGenerator::global()->generate(); - } -} - -void tst_bench_QCryptographicHash::hash_data() -{ - QTest::addColumn("algorithm"); - QTest::addColumn("data"); - - static const int datasizes[] = { 0, 1, 64, 65, 512, 4095, 4096, 4097, 65536 }; - for (uint i = 0; i < sizeof(datasizes)/sizeof(datasizes[0]); ++i) { - Q_ASSERT(datasizes[i] < MaxBlockSize); - QByteArray data = QByteArray::fromRawData(blockOfData.constData(), datasizes[i]); - - for (int algo = QCryptographicHash::Md4; algo <= MaxCryptoAlgorithm; ++algo) - QTest::newRow(algoname(algo) + QByteArray::number(datasizes[i])) << algo << data; - } -} - -void tst_bench_QCryptographicHash::hash() -{ - QFETCH(int, algorithm); - QFETCH(QByteArray, data); - - QCryptographicHash::Algorithm algo = QCryptographicHash::Algorithm(algorithm); - QBENCHMARK { - QCryptographicHash::hash(data, algo); - } -} - -void tst_bench_QCryptographicHash::addData() -{ - QFETCH(int, algorithm); - QFETCH(QByteArray, data); - - QCryptographicHash::Algorithm algo = QCryptographicHash::Algorithm(algorithm); - QCryptographicHash hash(algo); - QBENCHMARK { - hash.reset(); - hash.addData(data); - hash.result(); - } -} - -void tst_bench_QCryptographicHash::addDataChunked() -{ - QFETCH(int, algorithm); - QFETCH(QByteArray, data); - - QCryptographicHash::Algorithm algo = QCryptographicHash::Algorithm(algorithm); - QCryptographicHash hash(algo); - QBENCHMARK { - hash.reset(); - - // add the data in chunks of 64 bytes - for (int i = 0; i < data.size() / 64; ++i) - hash.addData(data.constData() + 64 * i, 64); - hash.addData(data.constData() + data.size() / 64 * 64, data.size() % 64); - - hash.result(); - } -} - -QTEST_APPLESS_MAIN(tst_bench_QCryptographicHash) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/tools/qcryptographichash/tst_bench_qcryptographichash.cpp b/tests/benchmarks/corelib/tools/qcryptographichash/tst_bench_qcryptographichash.cpp new file mode 100644 index 0000000000..bff3ddbc26 --- /dev/null +++ b/tests/benchmarks/corelib/tools/qcryptographichash/tst_bench_qcryptographichash.cpp @@ -0,0 +1,188 @@ +/**************************************************************************** +** +** Copyright (C) 2017 Intel Corporation. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module 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_QCryptographicHash : public QObject +{ + Q_OBJECT + QByteArray blockOfData; + +public: + tst_QCryptographicHash(); + +private Q_SLOTS: + void hash_data(); + void hash(); + void addData_data() { hash_data(); } + void addData(); + void addDataChunked_data() { hash_data(); } + void addDataChunked(); +}; + +const int MaxCryptoAlgorithm = QCryptographicHash::Sha3_512; +const int MaxBlockSize = 65536; + +const char *algoname(int i) +{ + switch (QCryptographicHash::Algorithm(i)) { + case QCryptographicHash::Md4: + return "md4-"; + case QCryptographicHash::Md5: + return "md5-"; + case QCryptographicHash::Sha1: + return "sha1-"; + case QCryptographicHash::Sha224: + return "sha2_224-"; + case QCryptographicHash::Sha256: + return "sha2_256-"; + case QCryptographicHash::Sha384: + return "sha2_384-"; + case QCryptographicHash::Sha512: + return "sha2_512-"; + case QCryptographicHash::Sha3_224: + return "sha3_224-"; + case QCryptographicHash::Sha3_256: + return "sha3_256-"; + case QCryptographicHash::Sha3_384: + return "sha3_384-"; + case QCryptographicHash::Sha3_512: + return "sha3_512-"; + case QCryptographicHash::Keccak_224: + return "keccak_224-"; + case QCryptographicHash::Keccak_256: + return "keccak_256-"; + case QCryptographicHash::Keccak_384: + return "keccak_384-"; + case QCryptographicHash::Keccak_512: + return "keccak_512-"; + case QCryptographicHash::Blake2b_160: + return "blake2b_160-"; + case QCryptographicHash::Blake2b_256: + return "blake2b_256-"; + case QCryptographicHash::Blake2b_384: + return "blake2b_384-"; + case QCryptographicHash::Blake2b_512: + return "blake2b_512-"; + case QCryptographicHash::Blake2s_128: + return "blake2s_128-"; + case QCryptographicHash::Blake2s_160: + return "blake2s_160-"; + case QCryptographicHash::Blake2s_224: + return "blake2s_224-"; + case QCryptographicHash::Blake2s_256: + return "blake2s_256-"; + } + Q_UNREACHABLE(); + return nullptr; +} + +tst_QCryptographicHash::tst_QCryptographicHash() + : blockOfData(MaxBlockSize, Qt::Uninitialized) +{ +#ifdef Q_OS_UNIX + QFile urandom("/dev/urandom"); + if (urandom.open(QIODevice::ReadOnly | QIODevice::Unbuffered)) { + QCOMPARE(urandom.read(blockOfData.data(), blockOfData.size()), qint64(MaxBlockSize)); + } else +#endif + { + for (int i = 0; i < MaxBlockSize; ++i) + blockOfData[i] = QRandomGenerator::global()->generate(); + } +} + +void tst_QCryptographicHash::hash_data() +{ + QTest::addColumn("algorithm"); + QTest::addColumn("data"); + + static const int datasizes[] = { 0, 1, 64, 65, 512, 4095, 4096, 4097, 65536 }; + for (uint i = 0; i < sizeof(datasizes)/sizeof(datasizes[0]); ++i) { + Q_ASSERT(datasizes[i] < MaxBlockSize); + QByteArray data = QByteArray::fromRawData(blockOfData.constData(), datasizes[i]); + + for (int algo = QCryptographicHash::Md4; algo <= MaxCryptoAlgorithm; ++algo) + QTest::newRow(algoname(algo) + QByteArray::number(datasizes[i])) << algo << data; + } +} + +void tst_QCryptographicHash::hash() +{ + QFETCH(int, algorithm); + QFETCH(QByteArray, data); + + QCryptographicHash::Algorithm algo = QCryptographicHash::Algorithm(algorithm); + QBENCHMARK { + QCryptographicHash::hash(data, algo); + } +} + +void tst_QCryptographicHash::addData() +{ + QFETCH(int, algorithm); + QFETCH(QByteArray, data); + + QCryptographicHash::Algorithm algo = QCryptographicHash::Algorithm(algorithm); + QCryptographicHash hash(algo); + QBENCHMARK { + hash.reset(); + hash.addData(data); + hash.result(); + } +} + +void tst_QCryptographicHash::addDataChunked() +{ + QFETCH(int, algorithm); + QFETCH(QByteArray, data); + + QCryptographicHash::Algorithm algo = QCryptographicHash::Algorithm(algorithm); + QCryptographicHash hash(algo); + QBENCHMARK { + hash.reset(); + + // add the data in chunks of 64 bytes + for (int i = 0; i < data.size() / 64; ++i) + hash.addData(data.constData() + 64 * i, 64); + hash.addData(data.constData() + data.size() / 64 * 64, data.size() % 64); + + hash.result(); + } +} + +QTEST_APPLESS_MAIN(tst_QCryptographicHash) + +#include "tst_bench_qcryptographichash.moc" diff --git a/tests/benchmarks/corelib/tools/qhash/CMakeLists.txt b/tests/benchmarks/corelib/tools/qhash/CMakeLists.txt index 5286484b0c..437ea285e8 100644 --- a/tests/benchmarks/corelib/tools/qhash/CMakeLists.txt +++ b/tests/benchmarks/corelib/tools/qhash/CMakeLists.txt @@ -1,12 +1,10 @@ -# Generated from qhash.pro. - ##################################################################### -## tst_hash Binary: +## tst_bench_qhash Binary: ##################################################################### -qt_internal_add_benchmark(tst_hash +qt_internal_add_benchmark(tst_bench_qhash SOURCES - main.cpp + tst_bench_qhash.cpp outofline.cpp INCLUDE_DIRECTORIES . diff --git a/tests/benchmarks/corelib/tools/qhash/main.cpp b/tests/benchmarks/corelib/tools/qhash/main.cpp deleted file mode 100644 index f9b1624fcc..0000000000 --- a/tests/benchmarks/corelib/tools/qhash/main.cpp +++ /dev/null @@ -1,173 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2016 Intel Corporation. -** 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 "main.h" - -#include -#include -#include -#include -#include -#include - - -class tst_QHash : public QObject -{ - Q_OBJECT - -private slots: - void initTestCase(); - void qhash_current_data() { data(); } - void qhash_current() { qhash_template(); } - void qhash_qt50_data() { data(); } - void qhash_qt50() { qhash_template(); } - void qhash_qt4_data() { data(); } - void qhash_qt4() { qhash_template(); } - void qhash_javaString_data() { data(); } - void qhash_javaString() { qhash_template(); } - - void hashing_current_data() { data(); } - void hashing_current() { hashing_template(); } - void hashing_qt50_data() { data(); } - void hashing_qt50() { hashing_template(); } - void hashing_qt4_data() { data(); } - void hashing_qt4() { hashing_template(); } - void hashing_javaString_data() { data(); } - void hashing_javaString() { hashing_template(); } - -private: - void data(); - template void qhash_template(); - template void hashing_template(); - - QStringList smallFilePaths; - QStringList uuids; - QStringList dict; - QStringList numbers; -}; - -///////////////////// QHash ///////////////////// - -#include - -void tst_QHash::initTestCase() -{ - // small list of file paths - QFile smallPathsData(QFINDTESTDATA("paths_small_data.txt")); - QVERIFY(smallPathsData.open(QIODevice::ReadOnly)); - smallFilePaths = QString::fromLatin1(smallPathsData.readAll()).split(QLatin1Char('\n')); - QVERIFY(!smallFilePaths.isEmpty()); - - // list of UUIDs - // guaranteed to be completely random, generated by http://xkcd.com/221/ - QUuid ns = QUuid("{f43d2ef3-2fe9-4563-a6f5-5a0100c2d699}"); - uuids.reserve(smallFilePaths.size()); - - foreach (const QString &path, smallFilePaths) - uuids.append(QUuid::createUuidV5(ns, path).toString()); - - - // lots of strings with alphabetical characters, vaguely reminiscent of - // a dictionary. - // - // this programatically generates a series like: - // AAAAAA - // AAAAAB - // AAAAAC - // ... - // AAAAAZ - // AAAABZ - // ... - // AAAAZZ - // AAABZZ - QByteArray id("AAAAAAA"); - - if (dict.isEmpty()) { - for (int i = id.length() - 1; i > 0;) { - dict.append(id); - char c = id.at(i); - id[i] = ++c; - - if (c == 'Z') { - // wrap to next digit - i--; - id[i] = 'A'; - } - } - } - - // string versions of numbers. - for (int i = 5000000; i < 5005001; ++i) - numbers.append(QString::number(i)); -} - -void tst_QHash::data() -{ - QTest::addColumn("items"); - QTest::newRow("paths-small") << smallFilePaths; - QTest::newRow("uuids-list") << uuids; - QTest::newRow("dictionary") << dict; - QTest::newRow("numbers") << numbers; -} - -template void tst_QHash::qhash_template() -{ - QFETCH(QStringList, items); - QHash hash; - - QList realitems; - foreach (const QString &s, items) - realitems.append(s); - - QBENCHMARK { - for (int i = 0, n = realitems.size(); i != n; ++i) { - hash[realitems.at(i)] = i; - } - } -} - -template void tst_QHash::hashing_template() -{ - // just the hashing function - QFETCH(QStringList, items); - - QList realitems; - realitems.reserve(items.size()); - foreach (const QString &s, items) - realitems.append(s); - - QBENCHMARK { - for (int i = 0, n = realitems.size(); i != n; ++i) - (void)qHash(realitems.at(i)); - } -} - -QTEST_MAIN(tst_QHash) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/tools/qhash/main.h b/tests/benchmarks/corelib/tools/qhash/main.h deleted file mode 100644 index eca4b61d58..0000000000 --- a/tests/benchmarks/corelib/tools/qhash/main.h +++ /dev/null @@ -1,61 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtTest module 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 - -struct Qt4String : QString -{ - Qt4String() {} - Qt4String(const QString &s) : QString(s) {} -}; - -QT_BEGIN_NAMESPACE -uint qHash(const Qt4String &); -QT_END_NAMESPACE - -struct Qt50String : QString -{ - Qt50String() {} - Qt50String(const QString &s) : QString(s) {} -}; - -QT_BEGIN_NAMESPACE -uint qHash(const Qt50String &, uint seed = 0); -QT_END_NAMESPACE - - -struct JavaString : QString -{ - JavaString() {} - JavaString(const QString &s) : QString(s) {} -}; - -QT_BEGIN_NAMESPACE -uint qHash(const JavaString &); -QT_END_NAMESPACE - diff --git a/tests/benchmarks/corelib/tools/qhash/outofline.cpp b/tests/benchmarks/corelib/tools/qhash/outofline.cpp index 4e449e76b4..795b2cbdc6 100644 --- a/tests/benchmarks/corelib/tools/qhash/outofline.cpp +++ b/tests/benchmarks/corelib/tools/qhash/outofline.cpp @@ -26,7 +26,7 @@ ** ****************************************************************************/ -#include "main.h" +#include "tst_bench_qhash.h" QT_BEGIN_NAMESPACE diff --git a/tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.cpp b/tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.cpp new file mode 100644 index 0000000000..30778a0c8c --- /dev/null +++ b/tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.cpp @@ -0,0 +1,174 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2016 Intel Corporation. +** 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 "tst_bench_qhash.h" + +#include +#include +#include +#include +#include +#include + + +class tst_QHash : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + void qhash_current_data() { data(); } + void qhash_current() { qhash_template(); } + void qhash_qt50_data() { data(); } + void qhash_qt50() { qhash_template(); } + void qhash_qt4_data() { data(); } + void qhash_qt4() { qhash_template(); } + void qhash_javaString_data() { data(); } + void qhash_javaString() { qhash_template(); } + + void hashing_current_data() { data(); } + void hashing_current() { hashing_template(); } + void hashing_qt50_data() { data(); } + void hashing_qt50() { hashing_template(); } + void hashing_qt4_data() { data(); } + void hashing_qt4() { hashing_template(); } + void hashing_javaString_data() { data(); } + void hashing_javaString() { hashing_template(); } + +private: + void data(); + template void qhash_template(); + template void hashing_template(); + + QStringList smallFilePaths; + QStringList uuids; + QStringList dict; + QStringList numbers; +}; + +///////////////////// QHash ///////////////////// + +#include + +void tst_QHash::initTestCase() +{ + // small list of strings (that happen to look like file paths produced long + // ago by cd ../.. && find . -print, but that's irrelevant). + QFile smallPathsData(QFINDTESTDATA("paths_small_data.txt")); + QVERIFY(smallPathsData.open(QIODevice::ReadOnly)); + smallFilePaths = QString::fromLatin1(smallPathsData.readAll()).split(QLatin1Char('\n')); + QVERIFY(!smallFilePaths.isEmpty()); + + // list of UUIDs + // guaranteed to be completely random, generated by http://xkcd.com/221/ + QUuid ns = QUuid("{f43d2ef3-2fe9-4563-a6f5-5a0100c2d699}"); + uuids.reserve(smallFilePaths.size()); + + foreach (const QString &path, smallFilePaths) + uuids.append(QUuid::createUuidV5(ns, path).toString()); + + + // lots of strings with alphabetical characters, vaguely reminiscent of + // a dictionary. + // + // this programatically generates a series like: + // AAAAAA + // AAAAAB + // AAAAAC + // ... + // AAAAAZ + // AAAABZ + // ... + // AAAAZZ + // AAABZZ + QByteArray id("AAAAAAA"); + + if (dict.isEmpty()) { + for (int i = id.length() - 1; i > 0;) { + dict.append(id); + char c = id.at(i); + id[i] = ++c; + + if (c == 'Z') { + // wrap to next digit + i--; + id[i] = 'A'; + } + } + } + + // string versions of numbers. + for (int i = 5000000; i < 5005001; ++i) + numbers.append(QString::number(i)); +} + +void tst_QHash::data() +{ + QTest::addColumn("items"); + QTest::newRow("paths-small") << smallFilePaths; + QTest::newRow("uuids-list") << uuids; + QTest::newRow("dictionary") << dict; + QTest::newRow("numbers") << numbers; +} + +template void tst_QHash::qhash_template() +{ + QFETCH(QStringList, items); + QHash hash; + + QList realitems; + foreach (const QString &s, items) + realitems.append(s); + + QBENCHMARK { + for (int i = 0, n = realitems.size(); i != n; ++i) { + hash[realitems.at(i)] = i; + } + } +} + +template void tst_QHash::hashing_template() +{ + // just the hashing function + QFETCH(QStringList, items); + + QList realitems; + realitems.reserve(items.size()); + foreach (const QString &s, items) + realitems.append(s); + + QBENCHMARK { + for (int i = 0, n = realitems.size(); i != n; ++i) + (void)qHash(realitems.at(i)); + } +} + +QTEST_MAIN(tst_QHash) + +#include "tst_bench_qhash.moc" diff --git a/tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.h b/tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.h new file mode 100644 index 0000000000..eca4b61d58 --- /dev/null +++ b/tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.h @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2016 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtTest module 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 + +struct Qt4String : QString +{ + Qt4String() {} + Qt4String(const QString &s) : QString(s) {} +}; + +QT_BEGIN_NAMESPACE +uint qHash(const Qt4String &); +QT_END_NAMESPACE + +struct Qt50String : QString +{ + Qt50String() {} + Qt50String(const QString &s) : QString(s) {} +}; + +QT_BEGIN_NAMESPACE +uint qHash(const Qt50String &, uint seed = 0); +QT_END_NAMESPACE + + +struct JavaString : QString +{ + JavaString() {} + JavaString(const QString &s) : QString(s) {} +}; + +QT_BEGIN_NAMESPACE +uint qHash(const JavaString &); +QT_END_NAMESPACE + diff --git a/tests/benchmarks/corelib/tools/qlist/CMakeLists.txt b/tests/benchmarks/corelib/tools/qlist/CMakeLists.txt index 46ca1c8514..6c9a96399f 100644 --- a/tests/benchmarks/corelib/tools/qlist/CMakeLists.txt +++ b/tests/benchmarks/corelib/tools/qlist/CMakeLists.txt @@ -1,12 +1,10 @@ -# Generated from qlist.pro. - ##################################################################### ## tst_bench_qlist Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qlist SOURCES - main.cpp + tst_bench_qlist.cpp PUBLIC_LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/tools/qlist/main.cpp b/tests/benchmarks/corelib/tools/qlist/main.cpp deleted file mode 100644 index 1f2f8553fe..0000000000 --- a/tests/benchmarks/corelib/tools/qlist/main.cpp +++ /dev/null @@ -1,501 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module 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 - -static const int N = 1000; - -struct MyBase -{ - MyBase(int i_) - : isCopy(false) - { - ++liveCount; - - i = i_; - } - - MyBase(const MyBase &other) - : isCopy(true) - { - if (isCopy) - ++copyCount; - ++liveCount; - - i = other.i; - } - - MyBase &operator=(const MyBase &other) - { - if (!isCopy) { - isCopy = true; - ++copyCount; - } else { - ++errorCount; - } - - i = other.i; - return *this; - } - - ~MyBase() - { - if (isCopy) { - if (!copyCount) - ++errorCount; - else - --copyCount; - } - if (!liveCount) - ++errorCount; - else - --liveCount; - } - - bool operator==(const MyBase &other) const - { return i == other.i; } - -protected: - ushort i; - bool isCopy; - -public: - static int errorCount; - static int liveCount; - static int copyCount; -}; - -int MyBase::errorCount = 0; -int MyBase::liveCount = 0; -int MyBase::copyCount = 0; - -struct MyPrimitive : public MyBase -{ - MyPrimitive(int i = -1) : MyBase(i) - { ++errorCount; } - MyPrimitive(const MyPrimitive &other) : MyBase(other) - { ++errorCount; } - MyPrimitive &operator=(const MyPrimitive &other) - { ++errorCount; MyBase::operator=(other); return *this; } - ~MyPrimitive() - { ++errorCount; } -}; - -struct MyMovable : public MyBase -{ - MyMovable(int i = -1) : MyBase(i) {} -}; - -struct MyComplex : public MyBase -{ - MyComplex(int i = -1) : MyBase(i) {} -}; - -QT_BEGIN_NAMESPACE - -Q_DECLARE_TYPEINFO(MyPrimitive, Q_PRIMITIVE_TYPE); -Q_DECLARE_TYPEINFO(MyMovable, Q_RELOCATABLE_TYPE); -Q_DECLARE_TYPEINFO(MyComplex, Q_COMPLEX_TYPE); - -QT_END_NAMESPACE - - -class tst_QList: public QObject -{ - Q_OBJECT - - const int million = 1000000; -private Q_SLOTS: - void removeAll_primitive_data(); - void removeAll_primitive() { removeAll_impl(); } - void removeAll_movable_data() { removeAll_primitive_data(); } - void removeAll_movable() { removeAll_impl(); } - void removeAll_complex_data() { removeAll_primitive_data(); } - void removeAll_complex() { removeAll_impl(); } - - // append 1 element: - void appendOne_int_data() const { commonBenchmark_data(); } - void appendOne_primitive_data() const { commonBenchmark_data(); } - void appendOne_movable_data() const { commonBenchmark_data(); } - void appendOne_complex_data() const { commonBenchmark_data(); } - void appendOne_QString_data() const { commonBenchmark_data(); } - - void appendOne_int() const { appendOne_impl(); } // QTBUG-87330 - void appendOne_primitive() const { appendOne_impl(); } - void appendOne_movable() const { appendOne_impl(); } - void appendOne_complex() const { appendOne_impl(); } - void appendOne_QString() const { appendOne_impl(); } - - // prepend 1 element: - void prependOne_int_data() const { commonBenchmark_data(); } - void prependOne_primitive_data() const { commonBenchmark_data(); } - void prependOne_movable_data() const { commonBenchmark_data(); } - void prependOne_complex_data() const { commonBenchmark_data(); } - void prependOne_QString_data() const { commonBenchmark_data(); } - - void prependOne_int() const { prependOne_impl(); } - void prependOne_primitive() const { prependOne_impl(); } - void prependOne_movable() const { prependOne_impl(); } - void prependOne_complex() const { prependOne_impl(); } - void prependOne_QString() const { prependOne_impl(); } - - // insert in middle 1 element (quadratic, slow): - void midInsertOne_int_data() const { commonBenchmark_data(million); } - void midInsertOne_primitive_data() const { commonBenchmark_data(million); } - void midInsertOne_movable_data() const { commonBenchmark_data(million); } - void midInsertOne_complex_data() const { commonBenchmark_data(million / 10); } - void midInsertOne_QString_data() const { commonBenchmark_data(million / 10); } - - void midInsertOne_int() const { midInsertOne_impl(); } - void midInsertOne_primitive() const { midInsertOne_impl(); } - void midInsertOne_movable() const { midInsertOne_impl(); } - void midInsertOne_complex() const { midInsertOne_impl(); } - void midInsertOne_QString() const { midInsertOne_impl(); } - - // append/prepend 1 element - hard times for branch predictor: - void appendPrependOne_int_data() const { commonBenchmark_data(); } - void appendPrependOne_primitive_data() const { commonBenchmark_data(); } - void appendPrependOne_movable_data() const { commonBenchmark_data(); } - void appendPrependOne_complex_data() const { commonBenchmark_data(); } - void appendPrependOne_QString_data() const { commonBenchmark_data(); } - - void appendPrependOne_int() const { appendPrependOne_impl(); } - void appendPrependOne_primitive() const { appendPrependOne_impl(); } - void appendPrependOne_movable() const { appendPrependOne_impl(); } - void appendPrependOne_complex() const { appendPrependOne_impl(); } - void appendPrependOne_QString() const { appendPrependOne_impl(); } - - // prepend half elements, then appen another half: - void prependAppendHalvesOne_int_data() const { commonBenchmark_data(); } - void prependAppendHalvesOne_primitive_data() const { commonBenchmark_data(); } - void prependAppendHalvesOne_movable_data() const { commonBenchmark_data(); } - void prependAppendHalvesOne_complex_data() const { commonBenchmark_data(); } - void prependAppendHalvesOne_QString_data() const { commonBenchmark_data(); } - - void prependAppendHalvesOne_int() const { prependAppendHalvesOne_impl(); } - void prependAppendHalvesOne_primitive() const - { - prependAppendHalvesOne_impl(); - } - void prependAppendHalvesOne_movable() const { prependAppendHalvesOne_impl(); } - void prependAppendHalvesOne_complex() const { prependAppendHalvesOne_impl(); } - void prependAppendHalvesOne_QString() const { prependAppendHalvesOne_impl(); } - - // emplace in middle 1 element (quadratic, slow): - void midEmplaceOne_int_data() const { commonBenchmark_data(million); } - void midEmplaceOne_primitive_data() const { commonBenchmark_data(million); } - void midEmplaceOne_movable_data() const { commonBenchmark_data(million); } - void midEmplaceOne_complex_data() const { commonBenchmark_data(million / 10); } - void midEmplaceOne_QString_data() const { commonBenchmark_data(million / 10); } - - void midEmplaceOne_int() const { midEmplaceOne_impl(); } - void midEmplaceOne_primitive() const { midEmplaceOne_impl(); } - void midEmplaceOne_movable() const { midEmplaceOne_impl(); } - void midEmplaceOne_complex() const { midEmplaceOne_impl(); } - void midEmplaceOne_QString() const { midEmplaceOne_impl(); } - - // remove from beginning in a general way - void removeFirstGeneral_int_data() const { commonBenchmark_data(); } - void removeFirstGeneral_primitive_data() const { commonBenchmark_data(); } - void removeFirstGeneral_movable_data() const { commonBenchmark_data(); } - void removeFirstGeneral_complex_data() const { commonBenchmark_data(); } - void removeFirstGeneral_QString_data() const { commonBenchmark_data(); } - - void removeFirstGeneral_int() const { removeFirstGeneral_impl(); } - void removeFirstGeneral_primitive() const { removeFirstGeneral_impl(); } - void removeFirstGeneral_movable() const { removeFirstGeneral_impl(); } - void removeFirstGeneral_complex() const { removeFirstGeneral_impl(); } - void removeFirstGeneral_QString() const { removeFirstGeneral_impl(); } - - // remove from beginning in a special way (using fast part of QList::removeFirst()) - void removeFirstSpecial_int_data() const { commonBenchmark_data(); } - void removeFirstSpecial_primitive_data() const { commonBenchmark_data(); } - void removeFirstSpecial_movable_data() const { commonBenchmark_data(); } - void removeFirstSpecial_complex_data() const { commonBenchmark_data(); } - void removeFirstSpecial_QString_data() const { commonBenchmark_data(); } - - void removeFirstSpecial_int() const { removeFirstSpecial_impl(); } - void removeFirstSpecial_primitive() const { removeFirstSpecial_impl(); } - void removeFirstSpecial_movable() const { removeFirstSpecial_impl(); } - void removeFirstSpecial_complex() const { removeFirstSpecial_impl(); } - void removeFirstSpecial_QString() const { removeFirstSpecial_impl(); } - -private: - template - void removeAll_impl() const; - - template - void commonBenchmark_data(int max = 200000000) const; - - template typename, typename> - void appendOne_impl() const; - - template typename, typename> - void prependOne_impl() const; - - template typename, typename> - void midInsertOne_impl() const; - - template typename, typename> - void appendPrependOne_impl() const; - - template typename, typename> - void prependAppendHalvesOne_impl() const; - - template typename, typename> - void midEmplaceOne_impl() const; - - template typename, typename> - void removeFirstGeneral_impl() const; - - template typename, typename> - void removeFirstSpecial_impl() const; -}; - -template -void tst_QList::removeAll_impl() const -{ - QFETCH(QList, i10); - QFETCH(int, itemsToRemove); - - constexpr int valueToRemove = 5; - constexpr bool isComplex = QTypeInfo::isComplex; - - MyBase::errorCount = 0; - MyBase::liveCount = 0; - MyBase::copyCount = 0; - { - QList list; - QCOMPARE(MyBase::liveCount, 0); - QCOMPARE(MyBase::copyCount, 0); - - for (int i = 0; i < 10 * N; ++i) { - T t(i10.at(i % 10)); - list.append(t); - } - QCOMPARE(MyBase::liveCount, isComplex ? list.size() : 0); - QCOMPARE(MyBase::copyCount, isComplex ? list.size() : 0); - - T t(valueToRemove); - QCOMPARE(MyBase::liveCount, isComplex ? list.size() + 1 : 1); - QCOMPARE(MyBase::copyCount, isComplex ? list.size() : 0); - - int removedCount = 0; // make compiler happy by setting to 0 - QList l; - - QBENCHMARK { - l = list; - removedCount = l.removeAll(t); - } - QCOMPARE(removedCount, itemsToRemove * N); - QCOMPARE(l.size() + removedCount, list.size()); - QVERIFY(!l.contains(valueToRemove)); - - QCOMPARE(MyBase::liveCount, - isComplex ? l.isDetached() ? list.size() + l.size() + 1 : list.size() + 1 : 1); - QCOMPARE(MyBase::copyCount, - isComplex ? l.isDetached() ? list.size() + l.size() : list.size() : 0); - } - if (isComplex) - QCOMPARE(MyBase::errorCount, 0); -} - -void tst_QList::removeAll_primitive_data() -{ - qRegisterMetaType >(); - - QTest::addColumn >("i10"); - QTest::addColumn("itemsToRemove"); - - QTest::newRow("0%") << QList(10, 0) << 0; - QTest::newRow("10%") << (QList() << 0 << 0 << 0 << 0 << 5 << 0 << 0 << 0 << 0 << 0) << 1; - QTest::newRow("90%") << (QList() << 5 << 5 << 5 << 5 << 0 << 5 << 5 << 5 << 5 << 5) << 9; - QTest::newRow("100%") << QList(10, 5) << 10; -} - -template -void tst_QList::commonBenchmark_data(int max) const -{ - QTest::addColumn("elemCount"); - - const auto addRow = [](int count, const char *text) { QTest::newRow(text) << count; }; - - const auto p = [](int i, const char *text) { return std::make_pair(i, text); }; - - // cap at 20m elements to allow 5.15/6.0 coverage to be the same - for (auto pair : { p(100, "100"), p(1000, "1k"), p(10000, "10k"), p(100000, "100k"), - p(1000000, "1m"), p(10000000, "10m"), p(20000000, "20m") }) { - if (pair.first <= max) - addRow(pair.first, pair.second); - } -} - -template typename Container, typename T> -void tst_QList::appendOne_impl() const -{ - QFETCH(int, elemCount); - constexpr auto getValue = []() { return T {}; }; - - QBENCHMARK { - Container container; - auto lvalue = getValue(); - - for (int i = 0; i < elemCount; ++i) { - container.append(lvalue); - } - } -} - -template typename Container, typename T> -void tst_QList::prependOne_impl() const -{ - QFETCH(int, elemCount); - constexpr auto getValue = []() { return T {}; }; - - QBENCHMARK { - Container container; - auto lvalue = getValue(); - - for (int i = 0; i < elemCount; ++i) { - container.prepend(lvalue); - } - } -} - -template typename Container, typename T> -void tst_QList::midInsertOne_impl() const -{ - QFETCH(int, elemCount); - constexpr auto getValue = []() { return T {}; }; - - QBENCHMARK { - Container container; - auto lvalue = getValue(); - - for (int i = 0; i < elemCount; ++i) { - const int remainder = i % 2; - // use insert(i, n, t) as insert(i, t) calls emplace (implementation - // detail) - container.insert(container.size() / 2 + remainder, 1, lvalue); - } - } -} - -template typename Container, typename T> -void tst_QList::appendPrependOne_impl() const -{ - QFETCH(int, elemCount); - constexpr auto getValue = []() { return T {}; }; - - QBENCHMARK { - Container container; - auto lvalue = getValue(); - - for (int i = 0; i < elemCount; ++i) { - if (i % 2 == 0) { - container.append(lvalue); - } else { - container.prepend(lvalue); - } - } - } -} - -template typename Container, typename T> -void tst_QList::prependAppendHalvesOne_impl() const -{ - QFETCH(int, elemCount); - constexpr auto getValue = []() { return T {}; }; - - QBENCHMARK { - Container container; - auto lvalue = getValue(); - - for (int i = 0; i < elemCount / 2; ++i) { - container.prepend(lvalue); - } - - for (int i = elemCount / 2; i < elemCount; ++i) { - container.append(lvalue); - } - } -} - -template typename Container, typename T> -void tst_QList::midEmplaceOne_impl() const -{ - QFETCH(int, elemCount); - constexpr auto getValue = []() { return T {}; }; - - QBENCHMARK { - Container container; - auto lvalue = getValue(); - - for (int i = 0; i < elemCount; ++i) { - const int remainder = i % 2; - container.emplace(container.size() / 2 + remainder, lvalue); - } - } -} - -template typename Container, typename T> -void tst_QList::removeFirstGeneral_impl() const -{ - QFETCH(int, elemCount); - constexpr auto getValue = []() { return T {}; }; - - QBENCHMARK { - Container container(elemCount, getValue()); - - for (int i = 0; i < elemCount - 1; ++i) { - container.remove(0, 1); - } - } -} - -template typename Container, typename T> -void tst_QList::removeFirstSpecial_impl() const -{ - QFETCH(int, elemCount); - constexpr auto getValue = []() { return T {}; }; - - QBENCHMARK { - Container container(elemCount, getValue()); - - for (int i = 0; i < elemCount; ++i) { - container.removeFirst(); - } - } -} - -QTEST_APPLESS_MAIN(tst_QList) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/tools/qlist/tst_bench_qlist.cpp b/tests/benchmarks/corelib/tools/qlist/tst_bench_qlist.cpp new file mode 100644 index 0000000000..d83e6eb61c --- /dev/null +++ b/tests/benchmarks/corelib/tools/qlist/tst_bench_qlist.cpp @@ -0,0 +1,501 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the QtCore module 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 + +static const int N = 1000; + +struct MyBase +{ + MyBase(int i_) + : isCopy(false) + { + ++liveCount; + + i = i_; + } + + MyBase(const MyBase &other) + : isCopy(true) + { + if (isCopy) + ++copyCount; + ++liveCount; + + i = other.i; + } + + MyBase &operator=(const MyBase &other) + { + if (!isCopy) { + isCopy = true; + ++copyCount; + } else { + ++errorCount; + } + + i = other.i; + return *this; + } + + ~MyBase() + { + if (isCopy) { + if (!copyCount) + ++errorCount; + else + --copyCount; + } + if (!liveCount) + ++errorCount; + else + --liveCount; + } + + bool operator==(const MyBase &other) const + { return i == other.i; } + +protected: + ushort i; + bool isCopy; + +public: + static int errorCount; + static int liveCount; + static int copyCount; +}; + +int MyBase::errorCount = 0; +int MyBase::liveCount = 0; +int MyBase::copyCount = 0; + +struct MyPrimitive : public MyBase +{ + MyPrimitive(int i = -1) : MyBase(i) + { ++errorCount; } + MyPrimitive(const MyPrimitive &other) : MyBase(other) + { ++errorCount; } + MyPrimitive &operator=(const MyPrimitive &other) + { ++errorCount; MyBase::operator=(other); return *this; } + ~MyPrimitive() + { ++errorCount; } +}; + +struct MyMovable : public MyBase +{ + MyMovable(int i = -1) : MyBase(i) {} +}; + +struct MyComplex : public MyBase +{ + MyComplex(int i = -1) : MyBase(i) {} +}; + +QT_BEGIN_NAMESPACE + +Q_DECLARE_TYPEINFO(MyPrimitive, Q_PRIMITIVE_TYPE); +Q_DECLARE_TYPEINFO(MyMovable, Q_RELOCATABLE_TYPE); +Q_DECLARE_TYPEINFO(MyComplex, Q_COMPLEX_TYPE); + +QT_END_NAMESPACE + + +class tst_QList: public QObject +{ + Q_OBJECT + + const int million = 1000000; +private Q_SLOTS: + void removeAll_primitive_data(); + void removeAll_primitive() { removeAll_impl(); } + void removeAll_movable_data() { removeAll_primitive_data(); } + void removeAll_movable() { removeAll_impl(); } + void removeAll_complex_data() { removeAll_primitive_data(); } + void removeAll_complex() { removeAll_impl(); } + + // append 1 element: + void appendOne_int_data() const { commonBenchmark_data(); } + void appendOne_primitive_data() const { commonBenchmark_data(); } + void appendOne_movable_data() const { commonBenchmark_data(); } + void appendOne_complex_data() const { commonBenchmark_data(); } + void appendOne_QString_data() const { commonBenchmark_data(); } + + void appendOne_int() const { appendOne_impl(); } // QTBUG-87330 + void appendOne_primitive() const { appendOne_impl(); } + void appendOne_movable() const { appendOne_impl(); } + void appendOne_complex() const { appendOne_impl(); } + void appendOne_QString() const { appendOne_impl(); } + + // prepend 1 element: + void prependOne_int_data() const { commonBenchmark_data(); } + void prependOne_primitive_data() const { commonBenchmark_data(); } + void prependOne_movable_data() const { commonBenchmark_data(); } + void prependOne_complex_data() const { commonBenchmark_data(); } + void prependOne_QString_data() const { commonBenchmark_data(); } + + void prependOne_int() const { prependOne_impl(); } + void prependOne_primitive() const { prependOne_impl(); } + void prependOne_movable() const { prependOne_impl(); } + void prependOne_complex() const { prependOne_impl(); } + void prependOne_QString() const { prependOne_impl(); } + + // insert in middle 1 element (quadratic, slow): + void midInsertOne_int_data() const { commonBenchmark_data(million); } + void midInsertOne_primitive_data() const { commonBenchmark_data(million); } + void midInsertOne_movable_data() const { commonBenchmark_data(million); } + void midInsertOne_complex_data() const { commonBenchmark_data(million / 10); } + void midInsertOne_QString_data() const { commonBenchmark_data(million / 10); } + + void midInsertOne_int() const { midInsertOne_impl(); } + void midInsertOne_primitive() const { midInsertOne_impl(); } + void midInsertOne_movable() const { midInsertOne_impl(); } + void midInsertOne_complex() const { midInsertOne_impl(); } + void midInsertOne_QString() const { midInsertOne_impl(); } + + // append/prepend 1 element - hard times for branch predictor: + void appendPrependOne_int_data() const { commonBenchmark_data(); } + void appendPrependOne_primitive_data() const { commonBenchmark_data(); } + void appendPrependOne_movable_data() const { commonBenchmark_data(); } + void appendPrependOne_complex_data() const { commonBenchmark_data(); } + void appendPrependOne_QString_data() const { commonBenchmark_data(); } + + void appendPrependOne_int() const { appendPrependOne_impl(); } + void appendPrependOne_primitive() const { appendPrependOne_impl(); } + void appendPrependOne_movable() const { appendPrependOne_impl(); } + void appendPrependOne_complex() const { appendPrependOne_impl(); } + void appendPrependOne_QString() const { appendPrependOne_impl(); } + + // prepend half elements, then appen another half: + void prependAppendHalvesOne_int_data() const { commonBenchmark_data(); } + void prependAppendHalvesOne_primitive_data() const { commonBenchmark_data(); } + void prependAppendHalvesOne_movable_data() const { commonBenchmark_data(); } + void prependAppendHalvesOne_complex_data() const { commonBenchmark_data(); } + void prependAppendHalvesOne_QString_data() const { commonBenchmark_data(); } + + void prependAppendHalvesOne_int() const { prependAppendHalvesOne_impl(); } + void prependAppendHalvesOne_primitive() const + { + prependAppendHalvesOne_impl(); + } + void prependAppendHalvesOne_movable() const { prependAppendHalvesOne_impl(); } + void prependAppendHalvesOne_complex() const { prependAppendHalvesOne_impl(); } + void prependAppendHalvesOne_QString() const { prependAppendHalvesOne_impl(); } + + // emplace in middle 1 element (quadratic, slow): + void midEmplaceOne_int_data() const { commonBenchmark_data(million); } + void midEmplaceOne_primitive_data() const { commonBenchmark_data(million); } + void midEmplaceOne_movable_data() const { commonBenchmark_data(million); } + void midEmplaceOne_complex_data() const { commonBenchmark_data(million / 10); } + void midEmplaceOne_QString_data() const { commonBenchmark_data(million / 10); } + + void midEmplaceOne_int() const { midEmplaceOne_impl(); } + void midEmplaceOne_primitive() const { midEmplaceOne_impl(); } + void midEmplaceOne_movable() const { midEmplaceOne_impl(); } + void midEmplaceOne_complex() const { midEmplaceOne_impl(); } + void midEmplaceOne_QString() const { midEmplaceOne_impl(); } + + // remove from beginning in a general way + void removeFirstGeneral_int_data() const { commonBenchmark_data(); } + void removeFirstGeneral_primitive_data() const { commonBenchmark_data(); } + void removeFirstGeneral_movable_data() const { commonBenchmark_data(); } + void removeFirstGeneral_complex_data() const { commonBenchmark_data(); } + void removeFirstGeneral_QString_data() const { commonBenchmark_data(); } + + void removeFirstGeneral_int() const { removeFirstGeneral_impl(); } + void removeFirstGeneral_primitive() const { removeFirstGeneral_impl(); } + void removeFirstGeneral_movable() const { removeFirstGeneral_impl(); } + void removeFirstGeneral_complex() const { removeFirstGeneral_impl(); } + void removeFirstGeneral_QString() const { removeFirstGeneral_impl(); } + + // remove from beginning in a special way (using fast part of QList::removeFirst()) + void removeFirstSpecial_int_data() const { commonBenchmark_data(); } + void removeFirstSpecial_primitive_data() const { commonBenchmark_data(); } + void removeFirstSpecial_movable_data() const { commonBenchmark_data(); } + void removeFirstSpecial_complex_data() const { commonBenchmark_data(); } + void removeFirstSpecial_QString_data() const { commonBenchmark_data(); } + + void removeFirstSpecial_int() const { removeFirstSpecial_impl(); } + void removeFirstSpecial_primitive() const { removeFirstSpecial_impl(); } + void removeFirstSpecial_movable() const { removeFirstSpecial_impl(); } + void removeFirstSpecial_complex() const { removeFirstSpecial_impl(); } + void removeFirstSpecial_QString() const { removeFirstSpecial_impl(); } + +private: + template + void removeAll_impl() const; + + template + void commonBenchmark_data(int max = 200000000) const; + + template typename, typename> + void appendOne_impl() const; + + template typename, typename> + void prependOne_impl() const; + + template typename, typename> + void midInsertOne_impl() const; + + template typename, typename> + void appendPrependOne_impl() const; + + template typename, typename> + void prependAppendHalvesOne_impl() const; + + template typename, typename> + void midEmplaceOne_impl() const; + + template typename, typename> + void removeFirstGeneral_impl() const; + + template typename, typename> + void removeFirstSpecial_impl() const; +}; + +template +void tst_QList::removeAll_impl() const +{ + QFETCH(QList, i10); + QFETCH(int, itemsToRemove); + + constexpr int valueToRemove = 5; + constexpr bool isComplex = QTypeInfo::isComplex; + + MyBase::errorCount = 0; + MyBase::liveCount = 0; + MyBase::copyCount = 0; + { + QList list; + QCOMPARE(MyBase::liveCount, 0); + QCOMPARE(MyBase::copyCount, 0); + + for (int i = 0; i < 10 * N; ++i) { + T t(i10.at(i % 10)); + list.append(t); + } + QCOMPARE(MyBase::liveCount, isComplex ? list.size() : 0); + QCOMPARE(MyBase::copyCount, isComplex ? list.size() : 0); + + T t(valueToRemove); + QCOMPARE(MyBase::liveCount, isComplex ? list.size() + 1 : 1); + QCOMPARE(MyBase::copyCount, isComplex ? list.size() : 0); + + int removedCount = 0; // make compiler happy by setting to 0 + QList l; + + QBENCHMARK { + l = list; + removedCount = l.removeAll(t); + } + QCOMPARE(removedCount, itemsToRemove * N); + QCOMPARE(l.size() + removedCount, list.size()); + QVERIFY(!l.contains(valueToRemove)); + + QCOMPARE(MyBase::liveCount, + isComplex ? l.isDetached() ? list.size() + l.size() + 1 : list.size() + 1 : 1); + QCOMPARE(MyBase::copyCount, + isComplex ? l.isDetached() ? list.size() + l.size() : list.size() : 0); + } + if (isComplex) + QCOMPARE(MyBase::errorCount, 0); +} + +void tst_QList::removeAll_primitive_data() +{ + qRegisterMetaType >(); + + QTest::addColumn >("i10"); + QTest::addColumn("itemsToRemove"); + + QTest::newRow("0%") << QList(10, 0) << 0; + QTest::newRow("10%") << (QList() << 0 << 0 << 0 << 0 << 5 << 0 << 0 << 0 << 0 << 0) << 1; + QTest::newRow("90%") << (QList() << 5 << 5 << 5 << 5 << 0 << 5 << 5 << 5 << 5 << 5) << 9; + QTest::newRow("100%") << QList(10, 5) << 10; +} + +template +void tst_QList::commonBenchmark_data(int max) const +{ + QTest::addColumn("elemCount"); + + const auto addRow = [](int count, const char *text) { QTest::newRow(text) << count; }; + + const auto p = [](int i, const char *text) { return std::make_pair(i, text); }; + + // cap at 20m elements to allow 5.15/6.0 coverage to be the same + for (auto pair : { p(100, "100"), p(1000, "1k"), p(10000, "10k"), p(100000, "100k"), + p(1000000, "1m"), p(10000000, "10m"), p(20000000, "20m") }) { + if (pair.first <= max) + addRow(pair.first, pair.second); + } +} + +template typename Container, typename T> +void tst_QList::appendOne_impl() const +{ + QFETCH(int, elemCount); + constexpr auto getValue = []() { return T {}; }; + + QBENCHMARK { + Container container; + auto lvalue = getValue(); + + for (int i = 0; i < elemCount; ++i) { + container.append(lvalue); + } + } +} + +template typename Container, typename T> +void tst_QList::prependOne_impl() const +{ + QFETCH(int, elemCount); + constexpr auto getValue = []() { return T {}; }; + + QBENCHMARK { + Container container; + auto lvalue = getValue(); + + for (int i = 0; i < elemCount; ++i) { + container.prepend(lvalue); + } + } +} + +template typename Container, typename T> +void tst_QList::midInsertOne_impl() const +{ + QFETCH(int, elemCount); + constexpr auto getValue = []() { return T {}; }; + + QBENCHMARK { + Container container; + auto lvalue = getValue(); + + for (int i = 0; i < elemCount; ++i) { + const int remainder = i % 2; + // use insert(i, n, t) as insert(i, t) calls emplace (implementation + // detail) + container.insert(container.size() / 2 + remainder, 1, lvalue); + } + } +} + +template typename Container, typename T> +void tst_QList::appendPrependOne_impl() const +{ + QFETCH(int, elemCount); + constexpr auto getValue = []() { return T {}; }; + + QBENCHMARK { + Container container; + auto lvalue = getValue(); + + for (int i = 0; i < elemCount; ++i) { + if (i % 2 == 0) { + container.append(lvalue); + } else { + container.prepend(lvalue); + } + } + } +} + +template typename Container, typename T> +void tst_QList::prependAppendHalvesOne_impl() const +{ + QFETCH(int, elemCount); + constexpr auto getValue = []() { return T {}; }; + + QBENCHMARK { + Container container; + auto lvalue = getValue(); + + for (int i = 0; i < elemCount / 2; ++i) { + container.prepend(lvalue); + } + + for (int i = elemCount / 2; i < elemCount; ++i) { + container.append(lvalue); + } + } +} + +template typename Container, typename T> +void tst_QList::midEmplaceOne_impl() const +{ + QFETCH(int, elemCount); + constexpr auto getValue = []() { return T {}; }; + + QBENCHMARK { + Container container; + auto lvalue = getValue(); + + for (int i = 0; i < elemCount; ++i) { + const int remainder = i % 2; + container.emplace(container.size() / 2 + remainder, lvalue); + } + } +} + +template typename Container, typename T> +void tst_QList::removeFirstGeneral_impl() const +{ + QFETCH(int, elemCount); + constexpr auto getValue = []() { return T {}; }; + + QBENCHMARK { + Container container(elemCount, getValue()); + + for (int i = 0; i < elemCount - 1; ++i) { + container.remove(0, 1); + } + } +} + +template typename Container, typename T> +void tst_QList::removeFirstSpecial_impl() const +{ + QFETCH(int, elemCount); + constexpr auto getValue = []() { return T {}; }; + + QBENCHMARK { + Container container(elemCount, getValue()); + + for (int i = 0; i < elemCount; ++i) { + container.removeFirst(); + } + } +} + +QTEST_APPLESS_MAIN(tst_QList) + +#include "tst_bench_qlist.moc" diff --git a/tests/benchmarks/corelib/tools/qrect/CMakeLists.txt b/tests/benchmarks/corelib/tools/qrect/CMakeLists.txt index 30234c7055..e3ce41f7be 100644 --- a/tests/benchmarks/corelib/tools/qrect/CMakeLists.txt +++ b/tests/benchmarks/corelib/tools/qrect/CMakeLists.txt @@ -1,15 +1,10 @@ -# Generated from qrect.pro. - ##################################################################### ## tst_bench_qrect Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qrect SOURCES - main.cpp + tst_bench_qrect.cpp PUBLIC_LIBRARIES Qt::Test ) - -#### Keys ignored in scope 1:.:.:qrect.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/tools/qrect/main.cpp b/tests/benchmarks/corelib/tools/qrect/main.cpp deleted file mode 100644 index 7ddf17845c..0000000000 --- a/tests/benchmarks/corelib/tools/qrect/main.cpp +++ /dev/null @@ -1,316 +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$ -** -****************************************************************************/ -// This file contains benchmarks for QRect/QRectF functions. - -#include -#include - -class tst_qrect : public QObject -{ - Q_OBJECT -private slots: - // QRect functions: - void contains_point_data(); - void contains_point(); - void contains_rect_data(); - void contains_rect(); - void intersects_data(); - void intersects(); - void intersected_data(); - void intersected(); - void united_data(); - void united(); - - // QRectF functions: - void contains_point_f_data(); - void contains_point_f(); - void contains_rect_f_data(); - void contains_rect_f(); - void intersects_f_data(); - void intersects_f(); - void intersected_f_data(); - void intersected_f(); - void united_f_data(); - void united_f(); -}; - -struct RectRectCombination -{ - QString tag; - qreal x1, y1, w1, h1, x2, y2, w2, h2; - RectRectCombination( - const QString &tag, - const qreal x1, const qreal y1, const qreal w1, const qreal h1, - const qreal x2, const qreal y2, const qreal w2, const qreal h2) - : tag(tag), x1(x1), y1(y1), w1(w1), h1(h1), x2(x2), y2(y2), w2(w2), h2(h2) {} -}; - -static QList createRectRectCombinations() -{ - QList result; - result << RectRectCombination("null", 0, 0, 0, 0, 0, 0, 0, 0); - result << RectRectCombination("null1", 0, 0, 0, 0, 0, 0, 10, 10); - result << RectRectCombination("null2", 0, 0, 10, 10, 0, 0, 0, 0); - - result << RectRectCombination("miss", 0, 0, 10, 10, 11, 11, 10, 10); - result << RectRectCombination("intersect", 0, 0, 10, 10, 5, 5, 10, 10); - result << RectRectCombination("contain1", 0, 0, 10, 10, 1, 1, 8, 8); - result << RectRectCombination("contain2", 1, 1, 8, 8, 0, 0, 10, 10); - - result << RectRectCombination("miss_flip1", 9, 9, -10, -10, 11, 11, 10, 10); - result << RectRectCombination("intersect_flip1", 9, 9, -10, -10, 5, 5, 10, 10); - result << RectRectCombination("contain1_flip1", 9, 9, -10, -10, 1, 1, 8, 8); - result << RectRectCombination("contain2_flip1", 8, 8, -8, -8, 0, 0, 10, 10); - - result << RectRectCombination("miss_flip2", 0, 0, 10, 10, 20, 20, -10, -10); - result << RectRectCombination("intersect_flip2", 0, 0, 10, 10, 14, 14, -10, -10); - result << RectRectCombination("contain1_flip2", 0, 0, 10, 10, 8, 8, -8, -8); - result << RectRectCombination("contain2_flip2", 1, 1, 8, 8, 9, 9, -10, -10); - - return result; -} - -static void addRectRectData(bool includeProperArg = false) -{ - QTest::addColumn("rf1"); - QTest::addColumn("rf2"); - if (includeProperArg) - QTest::addColumn("proper"); - for (int i = 0; i < (includeProperArg ? 2 : 1); ++i) { - QList combinations = createRectRectCombinations(); - foreach (RectRectCombination c, combinations) { - QTestData &testData = QTest::newRow(c.tag.toLatin1().data()); - QRectF r1(c.x1, c.y1, c.w1, c.h1); - QRectF r2(c.x2, c.y2, c.w2, c.h2); - testData << r1 << r2; - if (includeProperArg) - testData << (i == 0); - } - } -} - -struct RectPointCombination -{ - QString tag; - qreal x, y, w, h, px, py; - RectPointCombination( - const QString &tag, - const qreal x, const qreal y, const qreal w, const qreal h, const qreal px, const qreal py) - : tag(tag), x(x), y(y), w(w), h(h), px(px), py(py) {} -}; - -static QList createRectPointCombinations() -{ - QList result; - result << RectPointCombination("null", 0, 0, 0, 0, 0, 0); - - result << RectPointCombination("miss", 0, 0, 10, 10, -1, -1); - result << RectPointCombination("contain", 0, 0, 10, 10, 0, 0); - result << RectPointCombination("contain_proper", 0, 0, 10, 10, 1, 1); - - result << RectPointCombination("miss_flip", 9, 9, -10, -10, -1, -1); - result << RectPointCombination("contain_flip", 9, 9, -10, -10, 0, 0); - result << RectPointCombination("contain_flip_proper", 9, 9, -10, -10, 1, 1); - - return result; -} - -static void addRectPointData(bool includeProperArg = false) -{ - QTest::addColumn("rf"); - QTest::addColumn("pf"); - if (includeProperArg) - QTest::addColumn("proper"); - for (int i = 0; i < (includeProperArg ? 2 : 1); ++i) { - QList combinations = createRectPointCombinations(); - foreach (RectPointCombination c, combinations) { - QTestData &testData = QTest::newRow(c.tag.toLatin1().data()); - QRectF r(c.x, c.y, c.w, c.h); - QPointF p(c.px, c.py); - testData << r << p; - if (includeProperArg) - testData << (i == 0); - } - } -} - -void tst_qrect::contains_point_data() -{ - addRectPointData(true); -} - -void tst_qrect::contains_point() -{ - QFETCH(QRectF, rf); - QFETCH(QPointF, pf); - QFETCH(bool, proper); - QRect r(rf.toRect()); - QPoint p(pf.toPoint()); - QBENCHMARK { - r.contains(p, proper); - } -} - -void tst_qrect::contains_rect_data() -{ - addRectRectData(true); -} - -void tst_qrect::contains_rect() -{ - QFETCH(QRectF, rf1); - QFETCH(QRectF, rf2); - QFETCH(bool, proper); - QRect r1(rf1.toRect()); - QRect r2(rf2.toRect()); - QBENCHMARK { - r1.contains(r2, proper); - } -} - -void tst_qrect::intersects_data() -{ - addRectRectData(); -} - -void tst_qrect::intersects() -{ - QFETCH(QRectF, rf1); - QFETCH(QRectF, rf2); - QRect r1(rf1.toRect()); - QRect r2(rf2.toRect()); - QBENCHMARK { - r1.intersects(r2); - } -} - -void tst_qrect::intersected_data() -{ - addRectRectData(); -} - -void tst_qrect::intersected() -{ - QFETCH(QRectF, rf1); - QFETCH(QRectF, rf2); - QRect r1(rf1.toRect()); - QRect r2(rf2.toRect()); - QBENCHMARK { - Q_UNUSED(r1.intersected(r2)) - } -} - -void tst_qrect::united_data() -{ - addRectRectData(); -} - -void tst_qrect::united() -{ - QFETCH(QRectF, rf1); - QFETCH(QRectF, rf2); - QRect r1(rf1.toRect()); - QRect r2(rf2.toRect()); - QBENCHMARK { - Q_UNUSED(r1.united(r2)) - } -} - -void tst_qrect::contains_point_f_data() -{ - addRectPointData(); -} - -void tst_qrect::contains_point_f() -{ - QFETCH(QRectF, rf); - QFETCH(QPointF, pf); - QBENCHMARK { - rf.contains(pf); - } -} - -void tst_qrect::contains_rect_f_data() -{ - addRectRectData(); -} - -void tst_qrect::contains_rect_f() -{ - QFETCH(QRectF, rf1); - QFETCH(QRectF, rf2); - QBENCHMARK { - rf1.contains(rf2); - } -} - -void tst_qrect::intersects_f_data() -{ - addRectRectData(); -} - -void tst_qrect::intersects_f() -{ - QFETCH(QRectF, rf1); - QFETCH(QRectF, rf2); - QBENCHMARK { - rf1.intersects(rf2); - } -} - -void tst_qrect::intersected_f_data() -{ - addRectRectData(); -} - -void tst_qrect::intersected_f() -{ - QFETCH(QRectF, rf1); - QFETCH(QRectF, rf2); - QBENCHMARK { - Q_UNUSED(rf1.intersected(rf2)) - } -} - -void tst_qrect::united_f_data() -{ - addRectRectData(); -} - -void tst_qrect::united_f() -{ - QFETCH(QRectF, rf1); - QFETCH(QRectF, rf2); - QBENCHMARK { - Q_UNUSED(rf1.united(rf2)) - } -} - -QTEST_MAIN(tst_qrect) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/tools/qrect/tst_bench_qrect.cpp b/tests/benchmarks/corelib/tools/qrect/tst_bench_qrect.cpp new file mode 100644 index 0000000000..8850ede4f6 --- /dev/null +++ b/tests/benchmarks/corelib/tools/qrect/tst_bench_qrect.cpp @@ -0,0 +1,316 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ +// This file contains benchmarks for QRect/QRectF functions. + +#include +#include + +class tst_QRect : public QObject +{ + Q_OBJECT +private slots: + // QRect functions: + void contains_point_data(); + void contains_point(); + void contains_rect_data(); + void contains_rect(); + void intersects_data(); + void intersects(); + void intersected_data(); + void intersected(); + void united_data(); + void united(); + + // QRectF functions: + void contains_point_f_data(); + void contains_point_f(); + void contains_rect_f_data(); + void contains_rect_f(); + void intersects_f_data(); + void intersects_f(); + void intersected_f_data(); + void intersected_f(); + void united_f_data(); + void united_f(); +}; + +struct RectRectCombination +{ + QString tag; + qreal x1, y1, w1, h1, x2, y2, w2, h2; + RectRectCombination( + const QString &tag, + const qreal x1, const qreal y1, const qreal w1, const qreal h1, + const qreal x2, const qreal y2, const qreal w2, const qreal h2) + : tag(tag), x1(x1), y1(y1), w1(w1), h1(h1), x2(x2), y2(y2), w2(w2), h2(h2) {} +}; + +static QList createRectRectCombinations() +{ + QList result; + result << RectRectCombination("null", 0, 0, 0, 0, 0, 0, 0, 0); + result << RectRectCombination("null1", 0, 0, 0, 0, 0, 0, 10, 10); + result << RectRectCombination("null2", 0, 0, 10, 10, 0, 0, 0, 0); + + result << RectRectCombination("miss", 0, 0, 10, 10, 11, 11, 10, 10); + result << RectRectCombination("intersect", 0, 0, 10, 10, 5, 5, 10, 10); + result << RectRectCombination("contain1", 0, 0, 10, 10, 1, 1, 8, 8); + result << RectRectCombination("contain2", 1, 1, 8, 8, 0, 0, 10, 10); + + result << RectRectCombination("miss_flip1", 9, 9, -10, -10, 11, 11, 10, 10); + result << RectRectCombination("intersect_flip1", 9, 9, -10, -10, 5, 5, 10, 10); + result << RectRectCombination("contain1_flip1", 9, 9, -10, -10, 1, 1, 8, 8); + result << RectRectCombination("contain2_flip1", 8, 8, -8, -8, 0, 0, 10, 10); + + result << RectRectCombination("miss_flip2", 0, 0, 10, 10, 20, 20, -10, -10); + result << RectRectCombination("intersect_flip2", 0, 0, 10, 10, 14, 14, -10, -10); + result << RectRectCombination("contain1_flip2", 0, 0, 10, 10, 8, 8, -8, -8); + result << RectRectCombination("contain2_flip2", 1, 1, 8, 8, 9, 9, -10, -10); + + return result; +} + +static void addRectRectData(bool includeProperArg = false) +{ + QTest::addColumn("rf1"); + QTest::addColumn("rf2"); + if (includeProperArg) + QTest::addColumn("proper"); + for (int i = 0; i < (includeProperArg ? 2 : 1); ++i) { + QList combinations = createRectRectCombinations(); + foreach (RectRectCombination c, combinations) { + QTestData &testData = QTest::newRow(c.tag.toLatin1().data()); + QRectF r1(c.x1, c.y1, c.w1, c.h1); + QRectF r2(c.x2, c.y2, c.w2, c.h2); + testData << r1 << r2; + if (includeProperArg) + testData << (i == 0); + } + } +} + +struct RectPointCombination +{ + QString tag; + qreal x, y, w, h, px, py; + RectPointCombination( + const QString &tag, + const qreal x, const qreal y, const qreal w, const qreal h, const qreal px, const qreal py) + : tag(tag), x(x), y(y), w(w), h(h), px(px), py(py) {} +}; + +static QList createRectPointCombinations() +{ + QList result; + result << RectPointCombination("null", 0, 0, 0, 0, 0, 0); + + result << RectPointCombination("miss", 0, 0, 10, 10, -1, -1); + result << RectPointCombination("contain", 0, 0, 10, 10, 0, 0); + result << RectPointCombination("contain_proper", 0, 0, 10, 10, 1, 1); + + result << RectPointCombination("miss_flip", 9, 9, -10, -10, -1, -1); + result << RectPointCombination("contain_flip", 9, 9, -10, -10, 0, 0); + result << RectPointCombination("contain_flip_proper", 9, 9, -10, -10, 1, 1); + + return result; +} + +static void addRectPointData(bool includeProperArg = false) +{ + QTest::addColumn("rf"); + QTest::addColumn("pf"); + if (includeProperArg) + QTest::addColumn("proper"); + for (int i = 0; i < (includeProperArg ? 2 : 1); ++i) { + QList combinations = createRectPointCombinations(); + foreach (RectPointCombination c, combinations) { + QTestData &testData = QTest::newRow(c.tag.toLatin1().data()); + QRectF r(c.x, c.y, c.w, c.h); + QPointF p(c.px, c.py); + testData << r << p; + if (includeProperArg) + testData << (i == 0); + } + } +} + +void tst_QRect::contains_point_data() +{ + addRectPointData(true); +} + +void tst_QRect::contains_point() +{ + QFETCH(QRectF, rf); + QFETCH(QPointF, pf); + QFETCH(bool, proper); + QRect r(rf.toRect()); + QPoint p(pf.toPoint()); + QBENCHMARK { + r.contains(p, proper); + } +} + +void tst_QRect::contains_rect_data() +{ + addRectRectData(true); +} + +void tst_QRect::contains_rect() +{ + QFETCH(QRectF, rf1); + QFETCH(QRectF, rf2); + QFETCH(bool, proper); + QRect r1(rf1.toRect()); + QRect r2(rf2.toRect()); + QBENCHMARK { + r1.contains(r2, proper); + } +} + +void tst_QRect::intersects_data() +{ + addRectRectData(); +} + +void tst_QRect::intersects() +{ + QFETCH(QRectF, rf1); + QFETCH(QRectF, rf2); + QRect r1(rf1.toRect()); + QRect r2(rf2.toRect()); + QBENCHMARK { + r1.intersects(r2); + } +} + +void tst_QRect::intersected_data() +{ + addRectRectData(); +} + +void tst_QRect::intersected() +{ + QFETCH(QRectF, rf1); + QFETCH(QRectF, rf2); + QRect r1(rf1.toRect()); + QRect r2(rf2.toRect()); + QBENCHMARK { + Q_UNUSED(r1.intersected(r2)) + } +} + +void tst_QRect::united_data() +{ + addRectRectData(); +} + +void tst_QRect::united() +{ + QFETCH(QRectF, rf1); + QFETCH(QRectF, rf2); + QRect r1(rf1.toRect()); + QRect r2(rf2.toRect()); + QBENCHMARK { + Q_UNUSED(r1.united(r2)) + } +} + +void tst_QRect::contains_point_f_data() +{ + addRectPointData(); +} + +void tst_QRect::contains_point_f() +{ + QFETCH(QRectF, rf); + QFETCH(QPointF, pf); + QBENCHMARK { + rf.contains(pf); + } +} + +void tst_QRect::contains_rect_f_data() +{ + addRectRectData(); +} + +void tst_QRect::contains_rect_f() +{ + QFETCH(QRectF, rf1); + QFETCH(QRectF, rf2); + QBENCHMARK { + rf1.contains(rf2); + } +} + +void tst_QRect::intersects_f_data() +{ + addRectRectData(); +} + +void tst_QRect::intersects_f() +{ + QFETCH(QRectF, rf1); + QFETCH(QRectF, rf2); + QBENCHMARK { + rf1.intersects(rf2); + } +} + +void tst_QRect::intersected_f_data() +{ + addRectRectData(); +} + +void tst_QRect::intersected_f() +{ + QFETCH(QRectF, rf1); + QFETCH(QRectF, rf2); + QBENCHMARK { + Q_UNUSED(rf1.intersected(rf2)) + } +} + +void tst_QRect::united_f_data() +{ + addRectRectData(); +} + +void tst_QRect::united_f() +{ + QFETCH(QRectF, rf1); + QFETCH(QRectF, rf2); + QBENCHMARK { + Q_UNUSED(rf1.united(rf2)) + } +} + +QTEST_MAIN(tst_QRect) + +#include "tst_bench_qrect.moc" diff --git a/tests/benchmarks/corelib/tools/qringbuffer/CMakeLists.txt b/tests/benchmarks/corelib/tools/qringbuffer/CMakeLists.txt index 63128f5f95..23a2c990de 100644 --- a/tests/benchmarks/corelib/tools/qringbuffer/CMakeLists.txt +++ b/tests/benchmarks/corelib/tools/qringbuffer/CMakeLists.txt @@ -1,16 +1,11 @@ -# Generated from qringbuffer.pro. - ##################################################################### ## tst_bench_qringbuffer Binary: ##################################################################### qt_internal_add_benchmark(tst_bench_qringbuffer SOURCES - main.cpp + tst_bench_qringbuffer.cpp PUBLIC_LIBRARIES Qt::CorePrivate Qt::Test ) - -#### Keys ignored in scope 1:.:.:qringbuffer.pro:: -# TEMPLATE = "app" diff --git a/tests/benchmarks/corelib/tools/qringbuffer/main.cpp b/tests/benchmarks/corelib/tools/qringbuffer/main.cpp deleted file mode 100644 index fad30a4e34..0000000000 --- a/tests/benchmarks/corelib/tools/qringbuffer/main.cpp +++ /dev/null @@ -1,71 +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 tst_qringbuffer : public QObject -{ - Q_OBJECT -private slots: - void reserveAndRead(); - void free(); -}; - -void tst_qringbuffer::reserveAndRead() -{ - QRingBuffer ringBuffer; - QBENCHMARK { - for (qint64 i = 1; i < 256; ++i) - ringBuffer.reserve(i); - - for (qint64 i = 1; i < 256; ++i) - ringBuffer.read(0, i); - } -} - -void tst_qringbuffer::free() -{ - QRingBuffer ringBuffer; - QBENCHMARK { - ringBuffer.reserve(4096); - ringBuffer.reserve(2048); - ringBuffer.append(QByteArray("01234", 5)); - - ringBuffer.free(1); - ringBuffer.free(4096); - ringBuffer.free(48); - ringBuffer.free(2000); - } -} - -QTEST_MAIN(tst_qringbuffer) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/tools/qringbuffer/tst_bench_qringbuffer.cpp b/tests/benchmarks/corelib/tools/qringbuffer/tst_bench_qringbuffer.cpp new file mode 100644 index 0000000000..ab75688749 --- /dev/null +++ b/tests/benchmarks/corelib/tools/qringbuffer/tst_bench_qringbuffer.cpp @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** 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 tst_QRingBuffer : public QObject +{ + Q_OBJECT +private slots: + void reserveAndRead(); + void free(); +}; + +void tst_QRingBuffer::reserveAndRead() +{ + QRingBuffer ringBuffer; + QBENCHMARK { + for (qint64 i = 1; i < 256; ++i) + ringBuffer.reserve(i); + + for (qint64 i = 1; i < 256; ++i) + ringBuffer.read(0, i); + } +} + +void tst_QRingBuffer::free() +{ + QRingBuffer ringBuffer; + QBENCHMARK { + ringBuffer.reserve(4096); + ringBuffer.reserve(2048); + ringBuffer.append(QByteArray("01234", 5)); + + ringBuffer.free(1); + ringBuffer.free(4096); + ringBuffer.free(48); + ringBuffer.free(2000); + } +} + +QTEST_MAIN(tst_QRingBuffer) + +#include "tst_bench_qringbuffer.moc" diff --git a/tests/benchmarks/corelib/tools/qset/CMakeLists.txt b/tests/benchmarks/corelib/tools/qset/CMakeLists.txt index 00fd088776..844226c833 100644 --- a/tests/benchmarks/corelib/tools/qset/CMakeLists.txt +++ b/tests/benchmarks/corelib/tools/qset/CMakeLists.txt @@ -1,12 +1,10 @@ -# Generated from qset.pro. - ##################################################################### -## tst_qset Binary: +## tst_bench_qset Binary: ##################################################################### -qt_internal_add_benchmark(tst_qset +qt_internal_add_benchmark(tst_bench_qset SOURCES - main.cpp + tst_bench_qset.cpp PUBLIC_LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/tools/qset/main.cpp b/tests/benchmarks/corelib/tools/qset/main.cpp deleted file mode 100644 index f6c40ec160..0000000000 --- a/tests/benchmarks/corelib/tools/qset/main.cpp +++ /dev/null @@ -1,128 +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_QSet : public QObject -{ - Q_OBJECT - -private slots: - void intersect_int_data(); - void intersect_int(); - void intersect_complexType_data(); - void intersect_complexType(); -}; - -void tst_QSet::intersect_int_data() -{ - QTest::addColumn("lhsSize"); - QTest::addColumn("rhsSize"); - QTest::addColumn("intersectSize"); - - QTest::newRow("1000000.intersect(1000) = empty") << 1000000 << 1000 << 0; - QTest::newRow("1000.intersect(1000000) = empty") << 1000 << 1000000 << 0; - QTest::newRow("1000000.intersect(1000) = 500") << 1000000 << 1000 << 500; - QTest::newRow("1000.intersect(1000000) = 500") << 1000 << 1000000 << 500; - QTest::newRow("1000000.intersect(1000) = 1000") << 1000000 << 1000 << 1000; - QTest::newRow("1000.intersect(1000000) = 1000") << 1000 << 1000000 << 1000; -} - -void tst_QSet::intersect_int() -{ - QFETCH(int, lhsSize); - QFETCH(int, rhsSize); - QFETCH(int, intersectSize); - - // E.g. when lhsSize = 1000, rhsSize = 1000000 and intersectSize = 500: - // lhsSize = { 0, 1, ... 1000 } - // rhsSize = { 500, 501, ... 1000500 } - - QSet lhs; - for (int i = 0; i < lhsSize; ++i) - lhs.insert(i); - - QSet rhs; - const int start = lhsSize - intersectSize; - for (int i = start; i < start + rhsSize; ++i) - rhs.insert(i); - - QBENCHMARK { - lhs.intersect(rhs); - } - - QVERIFY(lhs.size() == intersectSize); -} - -struct ComplexType -{ - ComplexType(int a) : a(a) {} - int a; - int b; - int c; -}; - -inline uint qHash(const ComplexType &key, uint seed = 0) -{ - return uint(key.a) ^ seed; -} - -inline bool operator==(const ComplexType &lhs, const ComplexType &rhs) -{ - return lhs.a == rhs.a; -} - -void tst_QSet::intersect_complexType_data() -{ - intersect_int_data(); -} - -void tst_QSet::intersect_complexType() -{ - QFETCH(int, lhsSize); - QFETCH(int, rhsSize); - QFETCH(int, intersectSize); - - QSet lhs; - for (int i = 0; i < lhsSize; ++i) - lhs.insert(ComplexType(i)); - - QSet rhs; - const int start = lhsSize - intersectSize; - for (int i = start; i < start + rhsSize; ++i) - rhs.insert(ComplexType(i)); - - QBENCHMARK { - lhs.intersect(rhs); - } -} - -QTEST_MAIN(tst_QSet) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/tools/qset/tst_bench_qset.cpp b/tests/benchmarks/corelib/tools/qset/tst_bench_qset.cpp new file mode 100644 index 0000000000..4d873f8e39 --- /dev/null +++ b/tests/benchmarks/corelib/tools/qset/tst_bench_qset.cpp @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** 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_QSet : public QObject +{ + Q_OBJECT + +private slots: + void intersect_int_data(); + void intersect_int(); + void intersect_complexType_data(); + void intersect_complexType(); +}; + +void tst_QSet::intersect_int_data() +{ + QTest::addColumn("lhsSize"); + QTest::addColumn("rhsSize"); + QTest::addColumn("intersectSize"); + + QTest::newRow("1000000.intersect(1000) = empty") << 1000000 << 1000 << 0; + QTest::newRow("1000.intersect(1000000) = empty") << 1000 << 1000000 << 0; + QTest::newRow("1000000.intersect(1000) = 500") << 1000000 << 1000 << 500; + QTest::newRow("1000.intersect(1000000) = 500") << 1000 << 1000000 << 500; + QTest::newRow("1000000.intersect(1000) = 1000") << 1000000 << 1000 << 1000; + QTest::newRow("1000.intersect(1000000) = 1000") << 1000 << 1000000 << 1000; +} + +void tst_QSet::intersect_int() +{ + QFETCH(int, lhsSize); + QFETCH(int, rhsSize); + QFETCH(int, intersectSize); + + // E.g. when lhsSize = 1000, rhsSize = 1000000 and intersectSize = 500: + // lhsSize = { 0, 1, ... 1000 } + // rhsSize = { 500, 501, ... 1000500 } + + QSet lhs; + for (int i = 0; i < lhsSize; ++i) + lhs.insert(i); + + QSet rhs; + const int start = lhsSize - intersectSize; + for (int i = start; i < start + rhsSize; ++i) + rhs.insert(i); + + QBENCHMARK { + lhs.intersect(rhs); + } + + QVERIFY(lhs.size() == intersectSize); +} + +struct ComplexType +{ + ComplexType(int a) : a(a) {} + int a; + int b; + int c; +}; + +inline uint qHash(const ComplexType &key, uint seed = 0) +{ + return uint(key.a) ^ seed; +} + +inline bool operator==(const ComplexType &lhs, const ComplexType &rhs) +{ + return lhs.a == rhs.a; +} + +void tst_QSet::intersect_complexType_data() +{ + intersect_int_data(); +} + +void tst_QSet::intersect_complexType() +{ + QFETCH(int, lhsSize); + QFETCH(int, rhsSize); + QFETCH(int, intersectSize); + + QSet lhs; + for (int i = 0; i < lhsSize; ++i) + lhs.insert(ComplexType(i)); + + QSet rhs; + const int start = lhsSize - intersectSize; + for (int i = start; i < start + rhsSize; ++i) + rhs.insert(ComplexType(i)); + + QBENCHMARK { + lhs.intersect(rhs); + } +} + +QTEST_MAIN(tst_QSet) + +#include "tst_bench_qset.moc" diff --git a/tests/benchmarks/corelib/tools/qstack/CMakeLists.txt b/tests/benchmarks/corelib/tools/qstack/CMakeLists.txt index 4526af60db..9cd09a0699 100644 --- a/tests/benchmarks/corelib/tools/qstack/CMakeLists.txt +++ b/tests/benchmarks/corelib/tools/qstack/CMakeLists.txt @@ -1,12 +1,10 @@ -# Generated from qstack.pro. - ##################################################################### -## tst_bench_stack Binary: +## tst_bench_qstack Binary: ##################################################################### -qt_internal_add_benchmark(tst_bench_stack +qt_internal_add_benchmark(tst_bench_qstack SOURCES - main.cpp + tst_bench_qstack.cpp PUBLIC_LIBRARIES Qt::CorePrivate Qt::Test diff --git a/tests/benchmarks/corelib/tools/qstack/main.cpp b/tests/benchmarks/corelib/tools/qstack/main.cpp deleted file mode 100644 index c69e5c3ed8..0000000000 --- a/tests/benchmarks/corelib/tools/qstack/main.cpp +++ /dev/null @@ -1,84 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2015 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 - -#include - -class tst_QStack: public QObject -{ - Q_OBJECT - -private slots: - void qstack_push(); - void qstack_pop(); - void qstack_pushpopone(); -}; - -const int N = 1000000; - -void tst_QStack::qstack_push() -{ - QStack v; - QBENCHMARK { - for (int i = 0; i != N; ++i) - v.push(i); - v = QStack(); - } -} - -void tst_QStack::qstack_pop() -{ - QStack v; - for (int i = 0; i != N; ++i) - v.push(i); - - QBENCHMARK { - QStack v2 = v; - for (int i = 0; i != N; ++i) { - v2.pop(); - } - } -} - -void tst_QStack::qstack_pushpopone() -{ - QBENCHMARK { - QStack v; - for (int i = 0; i != N; ++i) { - v.push(0); - v.pop(); - } - } -} - -QTEST_MAIN(tst_QStack) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/tools/qstack/tst_bench_qstack.cpp b/tests/benchmarks/corelib/tools/qstack/tst_bench_qstack.cpp new file mode 100644 index 0000000000..2f17895f61 --- /dev/null +++ b/tests/benchmarks/corelib/tools/qstack/tst_bench_qstack.cpp @@ -0,0 +1,84 @@ +/**************************************************************************** +** +** Copyright (C) 2015 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 + +#include + +class tst_QStack: public QObject +{ + Q_OBJECT + +private slots: + void qstack_push(); + void qstack_pop(); + void qstack_pushpopone(); +}; + +const int N = 1000000; + +void tst_QStack::qstack_push() +{ + QStack v; + QBENCHMARK { + for (int i = 0; i != N; ++i) + v.push(i); + v = QStack(); + } +} + +void tst_QStack::qstack_pop() +{ + QStack v; + for (int i = 0; i != N; ++i) + v.push(i); + + QBENCHMARK { + QStack v2 = v; + for (int i = 0; i != N; ++i) { + v2.pop(); + } + } +} + +void tst_QStack::qstack_pushpopone() +{ + QBENCHMARK { + QStack v; + for (int i = 0; i != N; ++i) { + v.push(0); + v.pop(); + } + } +} + +QTEST_MAIN(tst_QStack) + +#include "tst_bench_qstack.moc" -- cgit v1.2.3