From 3febcd6286a3cd22db4f294e7f31a94c07c51fb0 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Wed, 25 Mar 2020 15:41:53 +0100 Subject: [PATCH] More startOfDay() fixes, in tst_bench_QDateTime MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../corelib/time/qdatetime/tst_bench_qdatetime.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tests/benchmarks/corelib/time/qdatetime/tst_bench_qdatetime.cpp b/tests/benchmarks/corelib/time/qdatetime/tst_bench_qdatetime.cpp index 302cf80abf1..59ef9a1e686 100644 --- a/tests/benchmarks/corelib/time/qdatetime/tst_bench_qdatetime.cpp +++ b/tests/benchmarks/corelib/time/qdatetime/tst_bench_qdatetime.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2016 The Qt Company Ltd. +** Copyright (C) 2022 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the QtCore module of the Qt Toolkit. @@ -107,7 +107,7 @@ QList tst_QDateTime::daily(qint64 start, qint64 end) QList list; list.reserve(end - start); 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; } @@ -117,15 +117,16 @@ QList tst_QDateTime::norse(qint64 start, qint64 end) QList list; list.reserve(end - start); 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; } void tst_QDateTime::create() { + const QTime noon = QTime::fromMSecsSinceStartOfDay(43200); QBENCHMARK { 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); } }