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.5 6.2 Task-number: QTBUG-124465 Change-Id: Ibd21e43d4c64aced33ba5b21e4602e0dc4fd7548 Reviewed-by: Mate Barany <mate.barany@qt.io> (cherry picked from commit 4467ebc837aded07b0b0cbc3b34ce67f2c0e96f3) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
d2473b30c4
commit
b19112dee4
@ -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"
|
||||
|
Loading…
x
Reference in New Issue
Block a user