diff options
Diffstat (limited to 'tests/benchmarks/corelib/text/qstring')
-rw-r--r-- | tests/benchmarks/corelib/text/qstring/CMakeLists.txt | 5 | ||||
-rw-r--r-- | tests/benchmarks/corelib/text/qstring/tst_bench_qstring.cpp | 256 |
2 files changed, 224 insertions, 37 deletions
diff --git a/tests/benchmarks/corelib/text/qstring/CMakeLists.txt b/tests/benchmarks/corelib/text/qstring/CMakeLists.txt index c2ce102780..f17088d2be 100644 --- a/tests/benchmarks/corelib/text/qstring/CMakeLists.txt +++ b/tests/benchmarks/corelib/text/qstring/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from qstring.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_bench_qstring Binary: @@ -7,6 +8,6 @@ qt_internal_add_benchmark(tst_bench_qstring SOURCES tst_bench_qstring.cpp - PUBLIC_LIBRARIES + LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/text/qstring/tst_bench_qstring.cpp b/tests/benchmarks/corelib/text/qstring/tst_bench_qstring.cpp index ada0e25d71..da5c0ff359 100644 --- a/tests/benchmarks/corelib/text/qstring/tst_bench_qstring.cpp +++ b/tests/benchmarks/corelib/text/qstring/tst_bench_qstring.cpp @@ -1,35 +1,14 @@ -/**************************************************************************** -** -** 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 <QByteArray> +#include <QLatin1StringView> #include <QFile> #include <QTest> #include <limits> +using namespace Qt::StringLiterals; + class tst_QString: public QObject { Q_OBJECT @@ -49,6 +28,7 @@ private slots: void toCaseFolded_data(); void toCaseFolded(); + // Serializing: void number_qlonglong_data(); void number_qlonglong() { number_impl<qlonglong>(); } void number_qulonglong_data(); @@ -57,10 +37,30 @@ private slots: void number_double_data(); void number_double(); + // Parsing: + void toLongLong_data(); + void toLongLong(); + void toULongLong_data(); + void toULongLong(); + void toDouble_data(); + void toDouble(); + + // operator=(~) +#if !defined(QT_NO_CAST_FROM_ASCII) && !defined(QT_RESTRICTED_CAST_FROM_ASCII) + void operator_assign_BA() { operator_assign<QByteArray>(); } + void operator_assign_BA_data() { operator_assign_data(); } + void operator_assign_char() { operator_assign<const char*>(); }; + void operator_assign_char_data() { operator_assign_data();} +#endif + void operator_assign_L1SV() { operator_assign<QLatin1StringView>(); } + void operator_assign_L1SV_data() { operator_assign_data(); } + private: void section_data_impl(bool includeRegExOnly = true); template <typename RX> void section_impl(); template <typename Integer> void number_impl(); + template <typename T> void operator_assign(); + void operator_assign_data(); }; tst_QString::tst_QString() @@ -214,6 +214,10 @@ void tst_QString::number_impl() template <typename Integer> void number_integer_common() { + QTest::addColumn<Integer>("number"); + QTest::addColumn<int>("base"); + QTest::addColumn<QString>("expected"); + QTest::newRow("0") << Integer(0ull) << 10 << QStringLiteral("0"); QTest::newRow("1234") << Integer(1234ull) << 10 << QStringLiteral("1234"); QTest::newRow("123456789") << Integer(123456789ull) << 10 << QStringLiteral("123456789"); @@ -225,10 +229,6 @@ void number_integer_common() void tst_QString::number_qlonglong_data() { - QTest::addColumn<qlonglong>("number"); - QTest::addColumn<int>("base"); - QTest::addColumn<QString>("expected"); - number_integer_common<qlonglong>(); QTest::newRow("-1234") << -1234ll << 10 << QStringLiteral("-1234"); @@ -255,10 +255,6 @@ void tst_QString::number_qlonglong_data() void tst_QString::number_qulonglong_data() { - QTest::addColumn<qulonglong>("number"); - QTest::addColumn<int>("base"); - QTest::addColumn<QString>("expected"); - number_integer_common<qulonglong>(); QTest::newRow("qlonglong-max + 1") @@ -319,6 +315,196 @@ void tst_QString::number_double() QCOMPARE(actual, expected); } +template <typename Integer> +void toWholeCommon_data() +{ + QTest::addColumn<QString>("text"); + QTest::addColumn<int>("base"); + QTest::addColumn<bool>("good"); + QTest::addColumn<Integer>("expected"); + + QTest::newRow("empty") << u""_s << 10 << false << Integer(0ull); + QTest::newRow("0") << u"0"_s << 10 << true << Integer(0ull); + QTest::newRow("1234") << u"1234"_s << 10 << true << Integer(1234ull); + QTest::newRow("1,234") << u"1,234"_s << 10 << false << Integer(0ull); + QTest::newRow("123456789") + << u"123456789"_s << 10 << true << Integer(123456789ull); + QTest::newRow("bad1dea, base 16") + << u"bad1dea"_s << 16 << true << Integer(0xBAD1DEAull); + QTest::newRow("bad1dea, base 10") << u"bad1dea"_s << 10 << false << Integer(0ull); + QTest::newRow("42, base 13") << u"42"_s << 13 << true << Integer(6ull * 9ull); + QTest::newRow("242, base 8") << u"242"_s << 8 << true << Integer(0242ull); + QTest::newRow("495, base 8") << u"495"_s << 8 << false << Integer(0ull); + QTest::newRow("101101, base 2") + << u"101101"_s << 2 << true << Integer(0b101101ull); + QTest::newRow("ad, base 30") << u"ad"_s << 30 << true << Integer(313ull); +} + +void tst_QString::toLongLong_data() +{ + toWholeCommon_data<qlonglong>(); + + QTest::newRow("-1234") << u"-1234"_s << 10 << true << -1234ll; + QTest::newRow("-123456789") << u"-123456789"_s << 10 << true << -123456789ll; + QTest::newRow("-bad1dea, base 16") << u"-bad1dea"_s << 16 << true << -0xBAD1DEAll; + QTest::newRow("-242, base 8") << u"-242"_s << 8 << true << -0242ll; + QTest::newRow("-101101, base 2") << u"-101101"_s << 2 << true << -0b101101ll; + QTest::newRow("-ad, base 30") << u"-ad"_s << 30 << true << -313ll; + + QTest::newRow("qlonglong-max") + << u"9223372036854775807"_s << 10 << true + << std::numeric_limits<qlonglong>::max(); + QTest::newRow("qlonglong-min") + << u"-9223372036854775808"_s << 10 << true + << std::numeric_limits<qlonglong>::min(); + QTest::newRow("qlonglong-max, base 2") + << QString(63, u'1') << 2 << true << std::numeric_limits<qlonglong>::max(); + QTest::newRow("qlonglong-min, base 2") + << (u"-1"_s + QString(63, u'0')) << 2 << true + << std::numeric_limits<qlonglong>::min(); + QTest::newRow("qlonglong-max, base 16") + << (QChar(u'7') + QString(15, u'f')) << 16 << true + << std::numeric_limits<qlonglong>::max(); + QTest::newRow("qlonglong-min, base 16") + << (u"-8"_s + QString(15, u'0')) << 16 << true + << std::numeric_limits<qlonglong>::min(); +} + +void tst_QString::toLongLong() +{ + QFETCH(QString, text); + QFETCH(int, base); + QFETCH(bool, good); + QFETCH(qlonglong, expected); + + qlonglong actual = expected; + bool ok = false; + QBENCHMARK { + actual = text.toLongLong(&ok, base); + } + QCOMPARE(ok, good); + QCOMPARE(actual, expected); +} + +void tst_QString::toULongLong_data() +{ + toWholeCommon_data<qulonglong>(); + + QTest::newRow("qlonglong-max + 1") + << u"9223372036854775808"_s << 10 << true + << (qulonglong(std::numeric_limits<qlonglong>::max()) + 1); + QTest::newRow("qulonglong-max") + << u"18446744073709551615"_s << 10 << true + << std::numeric_limits<qulonglong>::max(); + QTest::newRow("qulonglong-max, base 2") + << QString(64, u'1') << 2 << true << std::numeric_limits<qulonglong>::max(); + QTest::newRow("qulonglong-max, base 16") + << QString(16, u'f') << 16 << true << std::numeric_limits<qulonglong>::max(); +} + +void tst_QString::toULongLong() +{ + QFETCH(QString, text); + QFETCH(int, base); + QFETCH(bool, good); + QFETCH(qulonglong, expected); + + qulonglong actual = expected; + bool ok = false; + QBENCHMARK { + actual = text.toULongLong(&ok, base); + } + QCOMPARE(ok, good); + QCOMPARE(actual, expected); +} + +void tst_QString::toDouble_data() +{ + QTest::addColumn<QString>("text"); + QTest::addColumn<bool>("good"); + QTest::addColumn<double>("expected"); + + QTest::newRow("empty") << u""_s << false << 0.0; + QTest::newRow("0") << u"0"_s << true << 0.0; + QTest::newRow("0.12340") << u"0.12340"_s << true << 0.12340; + QTest::newRow("-0.12340") << u"-0.12340"_s << true << -0.12340; + QTest::newRow("epsilon") + << u"2.220446049e-16"_s << true << std::numeric_limits<double>::epsilon(); + QTest::newRow("1.0e-4") << u"1.0e-4"_s << true << 1.0e-4; + QTest::newRow("1.0e+4") << u"1.0e+4"_s << true << 1.0e+4; + QTest::newRow("10.e+3") << u"10.e+3"_s << true << 1.0e+4; + QTest::newRow("10e+3.") << u"10e+3."_s << false << 0.0; + QTest::newRow("1e4") << u"1e4"_s << true << 1.0e+4; + QTest::newRow("1.0e-8") << u"1.0e-8"_s << true << 1.0e-8; + QTest::newRow("1.0e+8") << u"1.0e+8"_s << true << 1.0e+8; + + // NaN and infinity: + QTest::newRow("nan") << u"nan"_s << true << qQNaN(); + QTest::newRow("NaN") << u"NaN"_s << true << qQNaN(); + QTest::newRow("-nan") << u"-nan"_s << false << 0.0; + QTest::newRow("+nan") << u"+nan"_s << false << 0.0; + QTest::newRow("inf") << u"inf"_s << true << qInf(); + QTest::newRow("Inf") << u"Inf"_s << true << qInf(); + QTest::newRow("+inf") << u"+inf"_s << true << qInf(); + QTest::newRow("-inf") << u"-inf"_s << true << -qInf(); +} + +void tst_QString::toDouble() +{ + QFETCH(QString, text); + QFETCH(bool, good); + QFETCH(double, expected); + + double actual = expected; + bool ok = false; + QBENCHMARK { + actual = text.toDouble(&ok); + } + QCOMPARE(ok, good); + QCOMPARE(actual, expected); +} + +template <typename T> void tst_QString::operator_assign() +{ + QFETCH(QByteArray, data); + QString str(data.size(), Qt::Uninitialized); + + T tdata; + if constexpr (std::is_same_v<T, const char*>) { + tdata = data.constData(); + } else if constexpr (std::is_same_v<T, QLatin1String>) { + tdata = T(data.constData(), data.size()); + } else { + tdata = T(data.constData(), data.size()); + tdata.detach(); + } + + QBENCHMARK { + str.operator=(tdata); + } +} + +void tst_QString::operator_assign_data() +{ + QTest::addColumn<QByteArray>("data"); + + QByteArray data; + data.fill('a', 5); + QTest::newRow("length: 5") << data; + data.fill('b', 10); + QTest::newRow("length: 10") << data; + data.fill('c', 20); + QTest::newRow("length: 20") << data; + data.fill('d', 50); + QTest::newRow("length: 50") << data; + data.fill('e', 100); + QTest::newRow("length: 100") << data; + data.fill('f', 500); + QTest::newRow("length: 500") << data; + data.fill('g', 1'000); + QTest::newRow("length: 1'000") << data; +} + QTEST_APPLESS_MAIN(tst_QString) #include "tst_bench_qstring.moc" |