diff options
Diffstat (limited to 'tests/benchmarks/corelib/text/qstringlist')
-rw-r--r-- | tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt | 7 | ||||
-rw-r--r-- | tests/benchmarks/corelib/text/qstringlist/tst_bench_qstringlist.cpp (renamed from tests/benchmarks/corelib/text/qstringlist/main.cpp) | 93 |
2 files changed, 58 insertions, 42 deletions
diff --git a/tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt b/tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt index 4649e3408a..da2f84d6e9 100644 --- a/tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt +++ b/tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from qstringlist.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_bench_qstringlist Binary: @@ -6,7 +7,7 @@ qt_internal_add_benchmark(tst_bench_qstringlist SOURCES - main.cpp - PUBLIC_LIBRARIES + tst_bench_qstringlist.cpp + LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/text/qstringlist/main.cpp b/tests/benchmarks/corelib/text/qstringlist/tst_bench_qstringlist.cpp index eb507c7c64..2431446bf6 100644 --- a/tests/benchmarks/corelib/text/qstringlist/main.cpp +++ b/tests/benchmarks/corelib/text/qstringlist/tst_bench_qstringlist.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 <QStringList> #include <QTest> @@ -33,6 +8,8 @@ #include <string> #include <vector> +using namespace Qt::StringLiterals; + class tst_QStringList: public QObject { Q_OBJECT @@ -44,6 +21,11 @@ private slots: void removeDuplicates() const; void removeDuplicates_data() const; + void filter_data() const; + void filter() const; + void filter_stringMatcher_data() const { filter_data(); } + void filter_stringMatcher() const; + void split_qlist_qbytearray() const; void split_qlist_qbytearray_data() const { return split_data(); } @@ -68,9 +50,9 @@ private: QStringList tst_QStringList::populateList(const int count, const QString &unit) { QStringList retval; - + retval.reserve(count); for (int i = 0; i < count; ++i) - retval.append(unit); + retval.append(unit + QString::number(i)); return retval; } @@ -93,7 +75,7 @@ void tst_QStringList::join() const QFETCH(QString, separator); QBENCHMARK { - input.join(separator); + [[maybe_unused]] auto r = input.join(separator); } } @@ -102,20 +84,20 @@ void tst_QStringList::join_data() const QTest::addColumn<QStringList>("input"); QTest::addColumn<QString>("separator"); - QTest::newRow("") + QTest::newRow("100") << populateList(100, QLatin1String("unit")) << QString(); - QTest::newRow("") + QTest::newRow("1000") << populateList(1000, QLatin1String("unit")) << QString(); - QTest::newRow("") - << populateList(10000, QLatin1String("unit")) + QTest::newRow("10000") + << populateList(10'000, QLatin1String("unit")) << QString(); - QTest::newRow("") - << populateList(100000, QLatin1String("unit")) + QTest::newRow("100000") + << populateList(100'000, QLatin1String("unit")) << QString(); } @@ -155,6 +137,39 @@ void tst_QStringList::removeDuplicates_data() const QTest::addRow("long-dup-0.75") << (l + l + l + l); } +void tst_QStringList::filter_data() const +{ + QTest::addColumn<QStringList>("list"); + QTest::addColumn<QStringList>("expected"); + + for (int i : {10, 20, 30, 40, 50, 70, 80, 100, 300, 500, 700, 900, 10'000}) { + QStringList list = populateList(i, u"A rather long string to test QStringMatcher"_s); + list.append(u"Horse and cart from old"_s); + QTest::addRow("list%d", i) << list << QStringList(u"Horse and cart from old"_s); + } +} + +void tst_QStringList::filter() const +{ + QFETCH(QStringList, list); + QFETCH(QStringList, expected); + + QBENCHMARK { + QCOMPARE(list.filter(u"Horse and cart from old", Qt::CaseSensitive), expected); + } +} + +void tst_QStringList::filter_stringMatcher() const +{ + QFETCH(QStringList, list); + QFETCH(QStringList, expected); + + const QStringMatcher matcher(u"Horse and cart from old", Qt::CaseSensitive); + QBENCHMARK { + QCOMPARE(list.filter(matcher), expected); + } +} + void tst_QStringList::split_data() const { QTest::addColumn<QString>("input"); @@ -173,7 +188,7 @@ void tst_QStringList::split_qlist_qbytearray() const QByteArray ba = input.toLatin1(); QBENCHMARK { - ba.split(splitChar); + [[maybe_unused]] auto r = ba.split(splitChar); } } @@ -183,7 +198,7 @@ void tst_QStringList::split_qlist_qstring() const const QChar splitChar = ':'; QBENCHMARK { - input.split(splitChar); + [[maybe_unused]] auto r = input.split(splitChar); } } @@ -237,4 +252,4 @@ void tst_QStringList::split_stdlist_stdstring() const QTEST_MAIN(tst_QStringList) -#include "main.moc" +#include "tst_bench_qstringlist.moc" |