summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/corelib/kernel/qmetatype
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmarks/corelib/kernel/qmetatype')
-rw-r--r--tests/benchmarks/corelib/kernel/qmetatype/CMakeLists.txt10
-rw-r--r--tests/benchmarks/corelib/kernel/qmetatype/qmetatype.pro6
-rw-r--r--tests/benchmarks/corelib/kernel/qmetatype/tst_bench_qmetatype.cpp (renamed from tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp)124
3 files changed, 54 insertions, 86 deletions
diff --git a/tests/benchmarks/corelib/kernel/qmetatype/CMakeLists.txt b/tests/benchmarks/corelib/kernel/qmetatype/CMakeLists.txt
index ae4bc9c906..f24a29d144 100644
--- a/tests/benchmarks/corelib/kernel/qmetatype/CMakeLists.txt
+++ b/tests/benchmarks/corelib/kernel/qmetatype/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qmetatype.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qmetatype Binary:
@@ -6,10 +7,7 @@
qt_internal_add_benchmark(tst_bench_qmetatype
SOURCES
- tst_qmetatype.cpp
- PUBLIC_LIBRARIES
+ tst_bench_qmetatype.cpp
+ LIBRARIES
Qt::Test
)
-
-#### Keys ignored in scope 1:.:.:qmetatype.pro:<TRUE>:
-# TEMPLATE = "app"
diff --git a/tests/benchmarks/corelib/kernel/qmetatype/qmetatype.pro b/tests/benchmarks/corelib/kernel/qmetatype/qmetatype.pro
deleted file mode 100644
index ffd36ad202..0000000000
--- a/tests/benchmarks/corelib/kernel/qmetatype/qmetatype.pro
+++ /dev/null
@@ -1,6 +0,0 @@
-TEMPLATE = app
-CONFIG += benchmark
-QT = core testlib
-
-TARGET = tst_bench_qmetatype
-SOURCES += tst_qmetatype.cpp
diff --git a/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/benchmarks/corelib/kernel/qmetatype/tst_bench_qmetatype.cpp
index abeaa79f26..94adfa4a8c 100644
--- a/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp
+++ b/tests/benchmarks/corelib/kernel/qmetatype/tst_bench_qmetatype.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <qtest.h>
#include <QtCore/qmetatype.h>
@@ -85,9 +60,8 @@ void tst_QMetaType::typeBuiltin_data()
{
QTest::addColumn<QByteArray>("typeName");
for (int i = 0; i < QMetaType::User; ++i) {
- const char *name = QMetaType::typeName(i);
- if (name)
- QTest::newRow(name) << QByteArray(name);
+ if (QMetaType metaType(i); metaType.isValid())
+ QTest::newRow(metaType.name()) << QByteArray(metaType.name());
}
}
@@ -98,7 +72,7 @@ void tst_QMetaType::typeBuiltin()
const char *nm = typeName.constData();
QBENCHMARK {
for (int i = 0; i < 100000; ++i)
- QMetaType::type(nm);
+ QMetaType::fromName(nm);
}
}
@@ -113,7 +87,7 @@ void tst_QMetaType::typeBuiltin_QByteArray()
QFETCH(QByteArray, typeName);
QBENCHMARK {
for (int i = 0; i < 100000; ++i)
- QMetaType::type(typeName);
+ QMetaType::fromName(typeName);
}
}
@@ -121,9 +95,8 @@ void tst_QMetaType::typeBuiltinNotNormalized_data()
{
QTest::addColumn<QByteArray>("typeName");
for (int i = 0; i < QMetaType::User; ++i) {
- const char *name = QMetaType::typeName(i);
- if (name)
- QTest::newRow(name) << QByteArray(name).append(" ");
+ if (QMetaType metaType(i); metaType.isValid())
+ QTest::newRow(metaType.name()) << QByteArray(metaType.name()).append(" ");
}
}
@@ -133,7 +106,7 @@ void tst_QMetaType::typeBuiltinNotNormalized()
const char *nm = typeName.constData();
QBENCHMARK {
for (int i = 0; i < 10000; ++i)
- QMetaType::type(nm);
+ QMetaType::fromName(nm);
}
}
@@ -144,7 +117,7 @@ void tst_QMetaType::typeCustom()
qRegisterMetaType<Foo>("Foo");
QBENCHMARK {
for (int i = 0; i < 10000; ++i)
- QMetaType::type("Foo");
+ QMetaType::fromName("Foo");
}
}
@@ -153,25 +126,25 @@ void tst_QMetaType::typeCustomNotNormalized()
qRegisterMetaType<Foo>("Foo");
QBENCHMARK {
for (int i = 0; i < 10000; ++i)
- QMetaType::type("Foo ");
+ QMetaType::fromName("Foo ");
}
}
void tst_QMetaType::typeNotRegistered()
{
- Q_ASSERT(QMetaType::type("Bar") == 0);
+ Q_ASSERT(!QMetaType::fromName("Bar").isValid());
QBENCHMARK {
for (int i = 0; i < 10000; ++i)
- QMetaType::type("Bar");
+ QMetaType::fromName("Bar");
}
}
void tst_QMetaType::typeNotRegisteredNotNormalized()
{
- Q_ASSERT(QMetaType::type("Bar") == 0);
+ Q_ASSERT(!QMetaType::fromName("Bar").isValid());
QBENCHMARK {
for (int i = 0; i < 10000; ++i)
- QMetaType::type("Bar ");
+ QMetaType::fromName("Bar ");
}
}
@@ -179,9 +152,8 @@ void tst_QMetaType::typeNameBuiltin_data()
{
QTest::addColumn<int>("type");
for (int i = 0; i < QMetaType::User; ++i) {
- const char *name = QMetaType::typeName(i);
- if (name)
- QTest::newRow(name) << i;
+ if (QMetaType metaType(i); metaType.isValid())
+ QTest::newRow(metaType.name()) << i;
}
}
@@ -190,7 +162,7 @@ void tst_QMetaType::typeNameBuiltin()
QFETCH(int, type);
QBENCHMARK {
for (int i = 0; i < 500000; ++i)
- QMetaType::typeName(type);
+ QMetaType(type).name();
}
}
@@ -199,17 +171,17 @@ void tst_QMetaType::typeNameCustom()
int type = qRegisterMetaType<Foo>("Foo");
QBENCHMARK {
for (int i = 0; i < 100000; ++i)
- QMetaType::typeName(type);
+ QMetaType(type).name();
}
}
void tst_QMetaType::typeNameNotRegistered()
{
// We don't care much about this case, but test it anyway.
- Q_ASSERT(QMetaType::typeName(-1) == 0);
+ Q_ASSERT(QMetaType(-1).name() == nullptr);
QBENCHMARK {
for (int i = 0; i < 500000; ++i)
- QMetaType::typeName(-1);
+ QMetaType(-1).name();
}
}
@@ -238,7 +210,7 @@ void tst_QMetaType::isRegisteredCustom()
void tst_QMetaType::isRegisteredNotRegistered()
{
- Q_ASSERT(QMetaType::typeName(-1) == 0);
+ Q_ASSERT(QMetaType(-1).name() == nullptr);
QBENCHMARK {
for (int i = 0; i < 100000; ++i)
QMetaType::isRegistered(-1);
@@ -248,9 +220,11 @@ void tst_QMetaType::isRegisteredNotRegistered()
void tst_QMetaType::constructInPlace_data()
{
QTest::addColumn<int>("typeId");
- for (int i = QMetaType::FirstCoreType; i <= QMetaType::LastCoreType; ++i)
- if (i != QMetaType::Void)
- QTest::newRow(QMetaType::typeName(i)) << i;
+ 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<BigClass>();
// GUI types are tested in tst_QGuiMetaType.
@@ -259,14 +233,15 @@ void tst_QMetaType::constructInPlace_data()
void tst_QMetaType::constructInPlace()
{
QFETCH(int, typeId);
- int size = QMetaType::sizeOf(typeId);
+ const QMetaType metaType(typeId);
+ size_t size = metaType.sizeOf();
void *storage = qMallocAligned(size, 2 * sizeof(qlonglong));
- QCOMPARE(QMetaType::construct(typeId, storage, /*copy=*/0), storage);
- QMetaType::destruct(typeId, storage);
+ QCOMPARE(metaType.construct(storage, /*copy=*/0), storage);
+ metaType.destruct(storage);
QBENCHMARK {
for (int i = 0; i < 100000; ++i) {
- QMetaType::construct(typeId, storage, /*copy=*/0);
- QMetaType::destruct(typeId, storage);
+ metaType.construct(storage, /*copy=*/0);
+ metaType.destruct(storage);
}
}
qFreeAligned(storage);
@@ -280,18 +255,19 @@ void tst_QMetaType::constructInPlaceCopy_data()
void tst_QMetaType::constructInPlaceCopy()
{
QFETCH(int, typeId);
- int size = QMetaType::sizeOf(typeId);
+ const QMetaType metaType(typeId);
+ size_t size = metaType.sizeOf();
void *storage = qMallocAligned(size, 2 * sizeof(qlonglong));
- void *other = QMetaType::create(typeId);
- QCOMPARE(QMetaType::construct(typeId, storage, other), storage);
- QMetaType::destruct(typeId, storage);
+ void *other = metaType.create();
+ QCOMPARE(metaType.construct(storage, other), storage);
+ metaType.destruct(storage);
QBENCHMARK {
for (int i = 0; i < 100000; ++i) {
- QMetaType::construct(typeId, storage, other);
- QMetaType::destruct(typeId, storage);
+ metaType.construct(storage, other);
+ metaType.destruct(storage);
}
}
- QMetaType::destroy(typeId, other);
+ metaType.destroy(other);
qFreeAligned(storage);
}
@@ -303,21 +279,21 @@ void tst_QMetaType::constructInPlaceCopyStaticLess_data()
void tst_QMetaType::constructInPlaceCopyStaticLess()
{
QFETCH(int, typeId);
- int size = QMetaType::sizeOf(typeId);
+ const QMetaType metaType(typeId);
+ size_t size = metaType.sizeOf();
void *storage = qMallocAligned(size, 2 * sizeof(qlonglong));
- void *other = QMetaType::create(typeId);
- QCOMPARE(QMetaType::construct(typeId, storage, other), storage);
- QMetaType::destruct(typeId, storage);
+ void *other = metaType.create();
+ QCOMPARE(metaType.construct(storage, other), storage);
+ metaType.destruct(storage);
QBENCHMARK {
- QMetaType type(typeId);
for (int i = 0; i < 100000; ++i) {
- type.construct(storage, other);
- type.destruct(storage);
+ metaType.construct(storage, other);
+ metaType.destruct(storage);
}
}
- QMetaType::destroy(typeId, other);
+ metaType.destroy(other);
qFreeAligned(storage);
}
QTEST_MAIN(tst_QMetaType)
-#include "tst_qmetatype.moc"
+#include "tst_bench_qmetatype.moc"