More startOfDay() fixes, in tst_bench_QDateTime

Update a QDateTime benchmark to use QDate::startOfDay() when setting
up its lists of date-times in helper functions, and to use noon as the
moment in the day in a creation test. Also move creation of a QTime
outside the loop: we're testing speed of creation of QDateTime here,
not QTime (and were already using the most trivial QTime constructor).

Change-Id: I26bf3369aae84a802ab03791f7341e107fede87c
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Edward Welbourne 2020-03-25 15:41:53 +01:00
parent 64dd5a8183
commit 3febcd6286

View File

@ -1,6 +1,6 @@
/**************************************************************************** /****************************************************************************
** **
** Copyright (C) 2016 The Qt Company Ltd. ** Copyright (C) 2022 The Qt Company Ltd.
** Contact: https://www.qt.io/licensing/ ** Contact: https://www.qt.io/licensing/
** **
** This file is part of the QtCore module of the Qt Toolkit. ** This file is part of the QtCore module of the Qt Toolkit.
@ -107,7 +107,7 @@ QList<QDateTime> tst_QDateTime::daily(qint64 start, qint64 end)
QList<QDateTime> list; QList<QDateTime> list;
list.reserve(end - start); list.reserve(end - start);
for (int jd = start; jd < end; ++jd) for (int jd = start; jd < end; ++jd)
list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); list.append(QDateTime(QDate::fromJulianDay(jd).startOfDay()));
return list; return list;
} }
@ -117,15 +117,16 @@ QList<QDateTime> tst_QDateTime::norse(qint64 start, qint64 end)
QList<QDateTime> list; QList<QDateTime> list;
list.reserve(end - start); list.reserve(end - start);
for (int jd = start; jd < end; ++jd) for (int jd = start; jd < end; ++jd)
list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet)); list.append(QDateTime(QDate::fromJulianDay(jd).startOfDay(cet)));
return list; return list;
} }
void tst_QDateTime::create() void tst_QDateTime::create()
{ {
const QTime noon = QTime::fromMSecsSinceStartOfDay(43200);
QBENCHMARK { QBENCHMARK {
for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) { for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) {
QDateTime test(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)); QDateTime test(QDate::fromJulianDay(jd), noon);
Q_UNUSED(test); Q_UNUSED(test);
} }
} }