diff options
author | Edward Welbourne <edward.welbourne@qt.io> | 2024-04-17 16:30:24 +0200 |
---|---|---|
committer | Edward Welbourne <edward.welbourne@qt.io> | 2024-04-22 18:56:21 +0200 |
commit | 4467ebc837aded07b0b0cbc3b34ce67f2c0e96f3 (patch) | |
tree | 077a6c709ee5e97af28a87cd64d2bfc40c5f99df | |
parent | cf0ebc9ad3a8a4de0faf995bf0e8e8da44979ec5 (diff) |
Add benchmarks for QDate::fromString()
These reveal a roughly factor of six slow-down for two valid date
formats and a roughly factor of twelve slow-down for an invalid one.
Pick-to: 6.7 6.5 6.2
Task-number: QTBUG-124465
Change-Id: Ibd21e43d4c64aced33ba5b21e4602e0dc4fd7548
Reviewed-by: Mate Barany <mate.barany@qt.io>
-rw-r--r-- | tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp b/tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp index 581c300d36..7dde3bf426 100644 --- a/tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp +++ b/tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp @@ -4,6 +4,7 @@ #include <QDate> #include <QTest> #include <QList> +using namespace Qt::StringLiterals; class tst_QDate : public QObject { @@ -33,6 +34,9 @@ private Q_SLOTS: void addDays(); void addMonths(); void addYears(); + + void fromString_data(); + void fromString(); }; QList<QDate> tst_QDate::daily(qint64 start, qint64 end) @@ -184,5 +188,28 @@ void tst_QDate::addYears() Q_UNUSED(store); } +void tst_QDate::fromString_data() +{ + QTest::addColumn<QString>("string"); + QTest::addColumn<QString>("format"); + QTest::addColumn<int>("baseYear"); + + QTest::newRow("yyyyMMdd") << u"20240412"_s << u"yyyyMMdd"_s << 2000; + QTest::newRow("yyyy-MM-dd") << u"2024-04-12"_s << u"yyyy-MM-dd"_s << 2000; + QTest::newRow("YYYYMMDD") << u"20240412"_s << u"YYYYMMDD"_s << 2000; // Invalid, QTBUG-124465. +} + +void tst_QDate::fromString() +{ + QFETCH(const QString, string); + QFETCH(const QString, format); + QFETCH(const int, baseYear); + QDate date; + QBENCHMARK { + date = QDate::fromString(string, format, baseYear); + } + Q_UNUSED(date); +} + QTEST_MAIN(tst_QDate) #include "tst_bench_qdate.moc" |