Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
6.6.0
-
None
-
macOS Ventura 13.5.2
MacBook Pro M1 Max 64 GB
-
-
2
-
be55fbede (dev), f5760cd7c (6.6), 270011ddb (tqtc/lts-6.5)
-
Foundations Sprint 94
Description
We noticed a significant drop in performance when comparing QDateTime values with a default value that is the minimum date for SQL server (1/1/1753). Some experimentation showed that all dates greater than 1900 perform fine but anything lower than that is quite a bit slower.
The following benchmark does the comparison with a bunch of random QDateTime/timezone combinations.
On my M1 Max MacBook Pro it has the following results:
- Qt 6.5.3: 6.017 msecs per iteration
- Qt 6.6.0: 10,822 msecs per iteration
#include <QTest> #include <QDateTime> #include <QTimeZone> class DateTimeBenchmark : public QObject{ Q_OBJECT private slots: void equal(); }; void DateTimeBenchmark::equal() { constexpr int iterations = 1000; constexpr int listSize = 100; QVector<QDateTime> list; list.reserve(listSize); // Init each list entry with random time within the next 60 days and random time zone const QDateTime start = QDateTime::currentDateTime(); const QDateTime end = QDateTime::currentDateTime().addDays(60); const auto availableTimeZones = QTimeZone::availableTimeZoneIds(); std::srand(12345); for(int i = 0; i < listSize; ++i) { QDateTime dateTime = start.addMSecs(std::rand() % start.msecsTo(end)); QTimeZone timeZone{availableTimeZones.at(std::rand() % availableTimeZones.size())}; dateTime.setTimeZone(timeZone); list.push_back(dateTime); } // Minimum date for SQL server QDateTime emptyQDateTime{QDate{1753, 1, 1}, QTime{0, 0, 0, 0}}; QBENCHMARK { for(int iter = 0; iter < iterations; ++iter) { for(const auto& t : list) { bool result = t == emptyQDateTime; Q_UNUSED(result); } } } } QTEST_GUILESS_MAIN(DateTimeBenchmark); #include "bench.moc"
Most of the time is spent comparing the time zone where lots of temporary memory is allocated/deallocated and conversions to NSString are made.
Attachments
Issue Links
- relates to
-
QTBUG-109201 toString() in macOS' system locale is very slow
- Open
-
QTBUG-104012 QDateTime constructor performance regression when year is below epoch
- Closed