From 9004a2412ba1f9976c2c61f01223dff852208c42 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 18 Aug 2021 11:48:29 +0200 Subject: Standardise layout and naming in corelib benchmarks Make file names match CMake's test names (and those follow dir-name) and class names follow tst_ClassName pattern when testing ClassName. Purge comments about the qmake configs the CMakeLists.txt are generated from. Purge empty constructors and init/cleanup methods of classes. Fix petty coding style violations. Add qdir/tree/, qurl, qbench and qset benchmarks to their parent directories' lists of subdirs. Fix unused return error from qurl benchmark. Change-Id: Ifc15a3a46e71cf82ad0637753517e0df34049763 Reviewed-by: Andrei Golubev Reviewed-by: Thiago Macieira --- .../corelib/kernel/qvariant/CMakeLists.txt | 4 +- .../corelib/kernel/qvariant/tst_bench_qvariant.cpp | 381 +++++++++++++++++++++ .../corelib/kernel/qvariant/tst_qvariant.cpp | 381 --------------------- 3 files changed, 382 insertions(+), 384 deletions(-) create mode 100644 tests/benchmarks/corelib/kernel/qvariant/tst_bench_qvariant.cpp delete mode 100644 tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp (limited to 'tests/benchmarks/corelib/kernel/qvariant') 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" -- cgit v1.2.3