summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/corelib/tools/qmap
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmarks/corelib/tools/qmap')
-rw-r--r--tests/benchmarks/corelib/tools/qmap/CMakeLists.txt9
-rw-r--r--tests/benchmarks/corelib/tools/qmap/qmap.pro6
-rw-r--r--tests/benchmarks/corelib/tools/qmap/tst_bench_qmap.cpp (renamed from tests/benchmarks/corelib/tools/qmap/main.cpp)149
3 files changed, 87 insertions, 77 deletions
diff --git a/tests/benchmarks/corelib/tools/qmap/CMakeLists.txt b/tests/benchmarks/corelib/tools/qmap/CMakeLists.txt
index b814b018c0..4dc3dbb258 100644
--- a/tests/benchmarks/corelib/tools/qmap/CMakeLists.txt
+++ b/tests/benchmarks/corelib/tools/qmap/CMakeLists.txt
@@ -1,14 +1,15 @@
-# Generated from qmap.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qmap Binary:
#####################################################################
-qt_add_benchmark(tst_bench_qmap
+qt_internal_add_benchmark(tst_bench_qmap
SOURCES
- main.cpp
+ tst_bench_qmap.cpp
INCLUDE_DIRECTORIES
.
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::Test
)
diff --git a/tests/benchmarks/corelib/tools/qmap/qmap.pro b/tests/benchmarks/corelib/tools/qmap/qmap.pro
deleted file mode 100644
index 0e06493c79..0000000000
--- a/tests/benchmarks/corelib/tools/qmap/qmap.pro
+++ /dev/null
@@ -1,6 +0,0 @@
-CONFIG += benchmark
-QT = core testlib
-
-INCLUDEPATH += .
-TARGET = tst_bench_qmap
-SOURCES += main.cpp
diff --git a/tests/benchmarks/corelib/tools/qmap/main.cpp b/tests/benchmarks/corelib/tools/qmap/tst_bench_qmap.cpp
index 50cc853df6..db3c4fc7a2 100644
--- a/tests/benchmarks/corelib/tools/qmap/main.cpp
+++ b/tests/benchmarks/corelib/tools/qmap/tst_bench_qmap.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) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QFile>
#include <QMap>
@@ -61,16 +36,41 @@ private slots:
void insertion_string_int2_hint();
void insertMap();
+
+private:
+ QStringList helloEachWorld(int count);
};
+QStringList tst_QMap::helloEachWorld(int count)
+{
+ QStringList result;
+ result.reserve(count);
+ result << QStringLiteral("Hello World"); // at index 0, not used
+
+ char16_t name[] = u"Hello World";
+ QStringView str(name);
+ for (int i = 1; i < count; ++i) {
+ auto p = name + 6; // In the gap between words.
+ for (const auto ch : QChar::fromUcs4(i))
+ p++[0] = ch;
+ result << str.toString();
+ }
+ return result;
+}
+
+constexpr int huge = 100000; // one hundred thousand; simple integral data tests
+// Sum of i with 0 <= i < huge; overflows, but that's OK as long as it's unsigned:
+constexpr uint hugeSum = (uint(huge) / 2) * uint(huge - 1);
+constexpr int bigish = 5000; // five thousand; tests using XString's expensive <
void tst_QMap::insertion_int_int()
{
QMap<int, int> map;
QBENCHMARK {
- for (int i = 0; i < 100000; ++i)
+ for (int i = 0; i < huge; ++i)
map.insert(i, i);
}
+ QCOMPARE(map.size(), qsizetype(huge));
}
void tst_QMap::insertion_int_intx()
@@ -79,36 +79,40 @@ void tst_QMap::insertion_int_intx()
// The results in the beginning of the test seems to be a somewhat inaccurate.
QMap<int, int> map;
QBENCHMARK {
- for (int i = 0; i < 100000; ++i)
+ for (int i = 0; i < huge; ++i)
map.insert(i, i);
}
+ QCOMPARE(map.size(), qsizetype(huge));
}
void tst_QMap::insertion_int_int_with_hint1()
{
QMap<int, int> map;
QBENCHMARK {
- for (int i = 0; i < 100000; ++i)
+ for (int i = 0; i < huge; ++i)
map.insert(map.constEnd(), i, i);
}
+ QCOMPARE(map.size(), qsizetype(huge));
}
void tst_QMap::insertion_int_int2()
{
QMap<int, int> map;
QBENCHMARK {
- for (int i = 100000; i >= 0; --i)
+ for (int i = huge; i >= 0; --i)
map.insert(i, i);
}
+ QCOMPARE(map.size(), qsizetype(huge) + 1);
}
void tst_QMap::insertion_int_int_with_hint2()
{
QMap<int, int> map;
QBENCHMARK {
- for (int i = 100000; i >= 0; --i)
+ for (int i = huge; i >= 0; --i)
map.insert(map.constBegin(), i, i);
}
+ QCOMPARE(map.size(), qsizetype(huge) + 1);
}
void tst_QMap::insertion_int_string()
@@ -116,93 +120,100 @@ void tst_QMap::insertion_int_string()
QMap<int, QString> map;
QString str("Hello World");
QBENCHMARK {
- for (int i = 0; i < 100000; ++i)
+ for (int i = 0; i < huge; ++i)
map.insert(i, str);
}
+ QCOMPARE(map.size(), qsizetype(huge));
}
void tst_QMap::insertion_string_int()
{
QMap<QString, int> map;
- QString str("Hello World");
+ const QStringList names = helloEachWorld(huge);
+ QCOMPARE(names.size(), qsizetype(huge));
QBENCHMARK {
- for (int i = 1; i < 100000; ++i) {
- str[0] = QChar(i);
- map.insert(str, i);
- }
+ for (int i = 1; i < huge; ++i)
+ map.insert(names.at(i), i);
}
+ QCOMPARE(map.size() + 1, qsizetype(huge));
}
-
void tst_QMap::lookup_int_int()
{
QMap<int, int> map;
- for (int i = 0; i < 100000; ++i)
+ for (int i = 0; i < huge; ++i)
map.insert(i, i);
+ QCOMPARE(map.size(), qsizetype(huge));
- int sum = 0;
+ uint sum = 0, count = 0;
QBENCHMARK {
- for (int i = 0; i < 100000; ++i)
+ for (int i = 0; i < huge; ++i)
sum += map.value(i);
+ ++count;
}
+ QCOMPARE(sum, hugeSum * count);
}
void tst_QMap::lookup_int_string()
{
QMap<int, QString> map;
QString str("Hello World");
- for (int i = 0; i < 100000; ++i)
+ for (int i = 0; i < huge; ++i)
map.insert(i, str);
+ QCOMPARE(map.size(), qsizetype(huge));
QBENCHMARK {
- for (int i = 0; i < 100000; ++i)
- str += map.value(i);
+ for (int i = 0; i < huge; ++i)
+ str = map.value(i);
}
}
void tst_QMap::lookup_string_int()
{
QMap<QString, int> map;
- QString str("Hello World");
- for (int i = 1; i < 100000; ++i) {
- str[0] = QChar(i);
- map.insert(str, i);
- }
+ const QStringList names = helloEachWorld(huge);
+ for (int i = 1; i < huge; ++i)
+ map.insert(names.at(i), i);
+ QCOMPARE(map.size() + 1, qsizetype(huge));
- int sum = 0;
+ uint sum = 0, count = 0;
QBENCHMARK {
- for (int i = 1; i < 100000; ++i) {
- str[0] = QChar(i);
- sum += map.value(str);
- }
+ for (int i = 1; i < huge; ++i)
+ sum += map.value(names.at(i));
+ ++count;
}
+ QCOMPARE(sum, hugeSum * count);
}
// iteration speed doesn't depend on the type of the map.
void tst_QMap::iteration()
{
QMap<int, int> map;
- for (int i = 0; i < 100000; ++i)
+ for (int i = 0; i < huge; ++i)
map.insert(i, i);
+ QCOMPARE(map.size(), qsizetype(huge));
- int j = 0;
+ uint sum = 0, count = 0;
QBENCHMARK {
for (int i = 0; i < 100; ++i) {
QMap<int, int>::const_iterator it = map.constBegin();
QMap<int, int>::const_iterator end = map.constEnd();
while (it != end) {
- j += *it;
+ sum += *it;
++it;
}
}
+ ++count;
}
+ QCOMPARE(sum, hugeSum * 100u * count);
}
void tst_QMap::toStdMap()
{
QMap<int, int> map;
- for (int i = 0; i < 100000; ++i)
+ for (int i = 0; i < huge; ++i)
map.insert(i, i);
+ QCOMPARE(map.size(), qsizetype(huge));
QBENCHMARK {
std::map<int, int> n = map.toStdMap();
@@ -213,11 +224,12 @@ void tst_QMap::toStdMap()
void tst_QMap::iterator_begin()
{
QMap<int, int> map;
- for (int i = 0; i < 100000; ++i)
+ for (int i = 0; i < huge; ++i)
map.insert(i, i);
+ QCOMPARE(map.size(), qsizetype(huge));
QBENCHMARK {
- for (int i = 0; i < 100000; ++i) {
+ for (int i = 0; i < huge; ++i) {
QMap<int, int>::const_iterator it = map.constBegin();
QMap<int, int>::const_iterator end = map.constEnd();
if (it == end) // same as if (false)
@@ -229,8 +241,9 @@ void tst_QMap::iterator_begin()
void tst_QMap::ctorStdMap()
{
std::map<int, int> map;
- for (int i = 0; i < 100000; ++i)
+ for (int i = 0; i < huge; ++i)
map.insert(std::pair<int, int>(i, i));
+ QCOMPARE(map.size(), size_t(huge));
QBENCHMARK {
QMap<int, int> qmap(map);
@@ -251,33 +264,35 @@ void tst_QMap::insertion_string_int2()
{
QMap<XString, int> map;
QBENCHMARK {
- for (int i = 1; i < 5000; ++i) {
+ for (int i = 1; i < bigish; ++i) {
XString str;
str.setNum(i);
map.insert(str, i);
}
}
+ QCOMPARE(map.size() + 1, qsizetype(bigish));
}
void tst_QMap::insertion_string_int2_hint()
{
QMap<XString, int> map;
QBENCHMARK {
- for (int i = 1; i < 5000; ++i) {
+ for (int i = 1; i < bigish; ++i) {
XString str;
str.setNum(i);
map.insert(map.end(), str, i);
}
}
+ QCOMPARE(map.size() + 1, qsizetype(bigish));
}
void tst_QMap::insertMap()
{
QMap<int, int> map;
- for (int i = 0; i < 100000; ++i)
+ for (int i = 0; i < huge; ++i)
map.insert(i * 4, 0);
QMap<int, int> map2;
- for (int i = 0; i < 50000; ++i)
+ for (int i = 0; i < huge / 2; ++i)
map2.insert(i * 7, 0);
QBENCHMARK_ONCE {
map.insert(map2);
@@ -286,4 +301,4 @@ void tst_QMap::insertMap()
QTEST_MAIN(tst_QMap)
-#include "main.moc"
+#include "tst_bench_qmap.moc"