diff options
Diffstat (limited to 'tests/benchmarks/corelib/text/qstringlist')
-rw-r--r-- | tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt | 5 | ||||
-rw-r--r-- | tests/benchmarks/corelib/text/qstringlist/tst_bench_qstringlist.cpp | 58 |
2 files changed, 53 insertions, 10 deletions
diff --git a/tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt b/tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt index 58af3c9dd3..da2f84d6e9 100644 --- a/tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt +++ b/tests/benchmarks/corelib/text/qstringlist/CMakeLists.txt @@ -1,3 +1,6 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + ##################################################################### ## tst_bench_qstringlist Binary: ##################################################################### @@ -5,6 +8,6 @@ qt_internal_add_benchmark(tst_bench_qstringlist SOURCES tst_bench_qstringlist.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/text/qstringlist/tst_bench_qstringlist.cpp b/tests/benchmarks/corelib/text/qstringlist/tst_bench_qstringlist.cpp index ee0789261c..2431446bf6 100644 --- a/tests/benchmarks/corelib/text/qstringlist/tst_bench_qstringlist.cpp +++ b/tests/benchmarks/corelib/text/qstringlist/tst_bench_qstringlist.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QStringList> #include <QTest> @@ -8,6 +8,8 @@ #include <string> #include <vector> +using namespace Qt::StringLiterals; + class tst_QStringList: public QObject { Q_OBJECT @@ -19,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(); } @@ -43,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; } @@ -77,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(); } @@ -130,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"); |