mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-05 16:55:25 +08:00
qt 6.5.1 original
This commit is contained in:
6
tests/benchmarks/corelib/time/CMakeLists.txt
Normal file
6
tests/benchmarks/corelib/time/CMakeLists.txt
Normal file
@ -0,0 +1,6 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
add_subdirectory(qdate)
|
||||
add_subdirectory(qdatetime)
|
||||
add_subdirectory(qtimezone)
|
13
tests/benchmarks/corelib/time/qdate/CMakeLists.txt
Normal file
13
tests/benchmarks/corelib/time/qdate/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## tst_bench_qdate Binary:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_benchmark(tst_bench_qdate
|
||||
SOURCES
|
||||
tst_bench_qdate.cpp
|
||||
LIBRARIES
|
||||
Qt::Test
|
||||
)
|
188
tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp
Normal file
188
tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp
Normal file
@ -0,0 +1,188 @@
|
||||
// Copyright (C) 2019 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QDate>
|
||||
#include <QTest>
|
||||
#include <QList>
|
||||
|
||||
class tst_QDate : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
enum : qint64
|
||||
{
|
||||
JULIAN_DAY_2010 = 2455198,
|
||||
JULIAN_DAY_2011 = 2455563,
|
||||
JULIAN_DAY_2020 = 2458850,
|
||||
};
|
||||
|
||||
static QList<QDate> daily(qint64 start, qint64 end);
|
||||
static QList<QDate> yearly(qint32 first, qint32 last);
|
||||
|
||||
private Q_SLOTS:
|
||||
void create();
|
||||
void year();
|
||||
void month();
|
||||
void day();
|
||||
void dayOfWeek();
|
||||
void dayOfYear();
|
||||
void monthLengths(); // isValid() and daysInMonth()
|
||||
void daysInYear();
|
||||
void isLeapYear();
|
||||
void getSetDate();
|
||||
void addDays();
|
||||
void addMonths();
|
||||
void addYears();
|
||||
};
|
||||
|
||||
QList<QDate> tst_QDate::daily(qint64 start, qint64 end)
|
||||
{
|
||||
QList<QDate> list;
|
||||
list.reserve(end - start);
|
||||
for (qint64 jd = start; jd < end; ++jd)
|
||||
list.append(QDate::fromJulianDay(jd));
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<QDate> tst_QDate::yearly(qint32 first, qint32 last)
|
||||
{
|
||||
QList<QDate> list;
|
||||
list.reserve(last + 1 - first);
|
||||
for (qint32 year = first; year <= last; ++year)
|
||||
list.append(QDate(year, 3, 21));
|
||||
return list;
|
||||
}
|
||||
|
||||
void tst_QDate::create()
|
||||
{
|
||||
QDate test;
|
||||
QBENCHMARK {
|
||||
for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
|
||||
test = QDate::fromJulianDay(jd);
|
||||
}
|
||||
Q_UNUSED(test);
|
||||
}
|
||||
|
||||
void tst_QDate::year()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDate &test : list)
|
||||
test.year();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDate::month()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDate &test : list)
|
||||
test.month();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDate::day()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDate &test : list)
|
||||
test.day();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDate::dayOfWeek()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDate &test : list)
|
||||
test.dayOfWeek();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDate::dayOfYear()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDate &test : list)
|
||||
test.dayOfYear();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDate::monthLengths()
|
||||
{
|
||||
bool check = true;
|
||||
QBENCHMARK {
|
||||
for (int year = 1900; year <= 2100; year++) {
|
||||
for (int month = 1; month <= 12; month++)
|
||||
check = QDate::isValid(year, month, QDate(year, month, 1).daysInMonth());
|
||||
}
|
||||
}
|
||||
Q_UNUSED(check);
|
||||
}
|
||||
|
||||
void tst_QDate::daysInYear()
|
||||
{
|
||||
const auto list = yearly(1601, 2401);
|
||||
QBENCHMARK {
|
||||
for (const QDate &date : list)
|
||||
date.daysInYear();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDate::isLeapYear()
|
||||
{
|
||||
QBENCHMARK {
|
||||
for (qint32 year = 1601; year <= 2401; year++)
|
||||
QDate::isLeapYear(year);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDate::getSetDate()
|
||||
{
|
||||
QDate store;
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const auto &test : list) {
|
||||
int year, month, day;
|
||||
test.getDate(&year, &month, &day);
|
||||
store.setDate(year, month, day);
|
||||
}
|
||||
}
|
||||
Q_UNUSED(store);
|
||||
}
|
||||
|
||||
void tst_QDate::addDays()
|
||||
{
|
||||
QDate store;
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const auto &test : list)
|
||||
store = test.addDays(17);
|
||||
}
|
||||
Q_UNUSED(store);
|
||||
}
|
||||
|
||||
void tst_QDate::addMonths()
|
||||
{
|
||||
QDate store;
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const auto &test : list)
|
||||
store = test.addMonths(17);
|
||||
}
|
||||
Q_UNUSED(store);
|
||||
}
|
||||
|
||||
void tst_QDate::addYears()
|
||||
{
|
||||
QDate store;
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const auto &test : list)
|
||||
store = test.addYears(17);
|
||||
}
|
||||
Q_UNUSED(store);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QDate)
|
||||
#include "tst_bench_qdate.moc"
|
14
tests/benchmarks/corelib/time/qdatetime/CMakeLists.txt
Normal file
14
tests/benchmarks/corelib/time/qdatetime/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## tst_bench_qdatetime Binary:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_benchmark(tst_bench_qdatetime
|
||||
SOURCES
|
||||
tst_bench_qdatetime.cpp
|
||||
LIBRARIES
|
||||
Qt::Test
|
||||
Qt::CorePrivate
|
||||
)
|
544
tests/benchmarks/corelib/time/qdatetime/tst_bench_qdatetime.cpp
Normal file
544
tests/benchmarks/corelib/time/qdatetime/tst_bench_qdatetime.cpp
Normal file
@ -0,0 +1,544 @@
|
||||
// Copyright (C) 2022 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QTimeZone>
|
||||
#include <QTest>
|
||||
#include <QList>
|
||||
#include <qdebug.h>
|
||||
#include <QtCore/private/qdatetime_p.h>
|
||||
|
||||
class tst_QDateTime : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
static QList<QDateTime> daily(qint64 start, qint64 end);
|
||||
static QList<QDateTime> norse(qint64 start, qint64 end);
|
||||
void decade_data();
|
||||
|
||||
private Q_SLOTS:
|
||||
void create_data() { decade_data(); }
|
||||
void create();
|
||||
void isNull();
|
||||
void isValid();
|
||||
void date();
|
||||
void time();
|
||||
void timeSpec();
|
||||
void offsetFromUtc();
|
||||
void timeZoneAbbreviation();
|
||||
void toMSecsSinceEpoch_data() { decade_data(); }
|
||||
void toMSecsSinceEpoch();
|
||||
void toMSecsSinceEpochTz_data() { decade_data(); }
|
||||
void toMSecsSinceEpochTz();
|
||||
void setDate();
|
||||
void setTime();
|
||||
#if QT_DEPRECATED_SINCE(6, 9)
|
||||
void setTimeSpec();
|
||||
void setOffsetFromUtc();
|
||||
#endif
|
||||
void setMSecsSinceEpoch();
|
||||
void setMSecsSinceEpochTz();
|
||||
void toString();
|
||||
void toStringTextFormat();
|
||||
void toStringIsoFormat();
|
||||
void addDays();
|
||||
void addDaysTz();
|
||||
void addMSecs();
|
||||
void addMSecsTz();
|
||||
#if QT_DEPRECATED_SINCE(6, 9)
|
||||
void toTimeSpec();
|
||||
void toOffsetFromUtc();
|
||||
#endif
|
||||
void daysTo();
|
||||
void msecsTo();
|
||||
void equivalent();
|
||||
void equivalentUtc();
|
||||
void lessThan();
|
||||
void lessThanUtc();
|
||||
void currentDateTime();
|
||||
void currentDate();
|
||||
void currentTime();
|
||||
void currentDateTimeUtc();
|
||||
void currentMSecsSinceEpoch();
|
||||
void fromString();
|
||||
void fromStringText();
|
||||
void fromStringIso();
|
||||
void fromMSecsSinceEpoch();
|
||||
void fromMSecsSinceEpochUtc();
|
||||
void fromMSecsSinceEpochTz();
|
||||
};
|
||||
|
||||
using namespace QtPrivate::DateTimeConstants;
|
||||
constexpr qint64 JULIAN_DAY_1 = 1721426;
|
||||
constexpr qint64 JULIAN_DAY_11 = 1725078;
|
||||
constexpr qint64 JULIAN_DAY_1890 = 2411369;
|
||||
constexpr qint64 JULIAN_DAY_1900 = 2415021;
|
||||
constexpr qint64 JULIAN_DAY_1950 = 2433283;
|
||||
constexpr qint64 JULIAN_DAY_1960 = 2436935;
|
||||
constexpr qint64 JULIAN_DAY_1970 = 2440588; // Epoch
|
||||
constexpr qint64 JULIAN_DAY_2010 = 2455198;
|
||||
constexpr qint64 JULIAN_DAY_2011 = 2455563;
|
||||
constexpr qint64 JULIAN_DAY_2020 = 2458850;
|
||||
constexpr qint64 JULIAN_DAY_2050 = 2469808;
|
||||
constexpr qint64 JULIAN_DAY_2060 = 2473460;
|
||||
|
||||
void tst_QDateTime::decade_data()
|
||||
{
|
||||
QTest::addColumn<qint64>("startJd");
|
||||
QTest::addColumn<qint64>("stopJd");
|
||||
|
||||
QTest::newRow("first-decade-CE") << JULIAN_DAY_1 << JULIAN_DAY_11;
|
||||
QTest::newRow("1890s") << JULIAN_DAY_1890 << JULIAN_DAY_1900;
|
||||
QTest::newRow("1950s") << JULIAN_DAY_1950 << JULIAN_DAY_1960;
|
||||
QTest::newRow("2010s") << JULIAN_DAY_2010 << JULIAN_DAY_2020;
|
||||
QTest::newRow("2050s") << JULIAN_DAY_2050 << JULIAN_DAY_2060;
|
||||
}
|
||||
|
||||
QList<QDateTime> tst_QDateTime::daily(qint64 start, qint64 end)
|
||||
{
|
||||
QList<QDateTime> list;
|
||||
list.reserve(end - start);
|
||||
for (int jd = start; jd < end; ++jd)
|
||||
list.append(QDateTime(QDate::fromJulianDay(jd).startOfDay()));
|
||||
return list;
|
||||
}
|
||||
|
||||
QList<QDateTime> tst_QDateTime::norse(qint64 start, qint64 end)
|
||||
{
|
||||
const QTimeZone cet("Europe/Oslo");
|
||||
QList<QDateTime> list;
|
||||
list.reserve(end - start);
|
||||
for (int jd = start; jd < end; ++jd)
|
||||
list.append(QDateTime(QDate::fromJulianDay(jd).startOfDay(cet)));
|
||||
return list;
|
||||
}
|
||||
|
||||
void tst_QDateTime::create()
|
||||
{
|
||||
QFETCH(const qint64, startJd);
|
||||
QFETCH(const qint64, stopJd);
|
||||
const QTime noon = QTime::fromMSecsSinceStartOfDay(43200);
|
||||
QBENCHMARK {
|
||||
for (int jd = startJd; jd < stopJd; ++jd) {
|
||||
QDateTime test(QDate::fromJulianDay(jd), noon);
|
||||
Q_UNUSED(test);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::isNull()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
test.isNull();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::isValid()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
test.isValid();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::date()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
test.date();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::time()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
test.time();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::timeSpec()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
test.timeSpec();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::offsetFromUtc()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
test.offsetFromUtc();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::timeZoneAbbreviation()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
test.timeZoneAbbreviation();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::toMSecsSinceEpoch()
|
||||
{
|
||||
QFETCH(const qint64, startJd);
|
||||
QFETCH(const qint64, stopJd);
|
||||
const auto list = daily(startJd, stopJd);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
test.toMSecsSinceEpoch();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::toMSecsSinceEpochTz()
|
||||
{
|
||||
QFETCH(const qint64, startJd);
|
||||
QFETCH(const qint64, stopJd);
|
||||
const auto list = norse(startJd, stopJd);
|
||||
|
||||
qint64 result;
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
result = test.toMSecsSinceEpoch();
|
||||
}
|
||||
Q_UNUSED(result);
|
||||
}
|
||||
|
||||
void tst_QDateTime::setDate()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (QDateTime test : list)
|
||||
test.setDate(QDate::fromJulianDay(JULIAN_DAY_2010));
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::setTime()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (QDateTime test : list)
|
||||
test.setTime(QTime(12, 0, 0));
|
||||
}
|
||||
}
|
||||
|
||||
#if QT_DEPRECATED_SINCE(6, 9)
|
||||
QT_WARNING_PUSH
|
||||
QT_WARNING_DISABLE_DEPRECATED
|
||||
void tst_QDateTime::setTimeSpec()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (QDateTime test : list)
|
||||
test.setTimeSpec(Qt::UTC);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::setOffsetFromUtc()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (QDateTime test : list)
|
||||
test.setOffsetFromUtc(3600);
|
||||
}
|
||||
}
|
||||
QT_WARNING_POP
|
||||
#endif // 6.9 deprecation
|
||||
|
||||
void tst_QDateTime::setMSecsSinceEpoch()
|
||||
{
|
||||
qint64 msecs = qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970 + 180) * MSECS_PER_DAY;
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (QDateTime test : list)
|
||||
test.setMSecsSinceEpoch(msecs);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::setMSecsSinceEpochTz()
|
||||
{
|
||||
const qint64 msecs = qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970 + 180) * MSECS_PER_DAY;
|
||||
const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (QDateTime test : list)
|
||||
test.setMSecsSinceEpoch(msecs);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::toString()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2011);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
test.toString(QStringLiteral("yyy-MM-dd hh:mm:ss.zzz t"));
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::toStringTextFormat()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2011);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
test.toString(Qt::TextDate);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::toStringIsoFormat()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2011);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
test.toString(Qt::ISODate);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::addDays()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QDateTime next;
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
next = test.addDays(1);
|
||||
}
|
||||
Q_UNUSED(next);
|
||||
}
|
||||
|
||||
void tst_QDateTime::addDaysTz()
|
||||
{
|
||||
const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
QDateTime result = test.addDays(1);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::addMSecs()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QDateTime next;
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
next = test.addMSecs(1);
|
||||
}
|
||||
Q_UNUSED(next);
|
||||
}
|
||||
|
||||
void tst_QDateTime::addMSecsTz()
|
||||
{
|
||||
const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
QDateTime result = test.addMSecs(1);
|
||||
}
|
||||
}
|
||||
|
||||
#if QT_DEPRECATED_SINCE(6, 9)
|
||||
QT_WARNING_PUSH
|
||||
QT_WARNING_DISABLE_DEPRECATED
|
||||
void tst_QDateTime::toTimeSpec()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
test.toTimeSpec(Qt::UTC);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::toOffsetFromUtc()
|
||||
{
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
test.toOffsetFromUtc(3600);
|
||||
}
|
||||
}
|
||||
QT_WARNING_POP
|
||||
#endif
|
||||
|
||||
void tst_QDateTime::daysTo()
|
||||
{
|
||||
const QDateTime other = QDateTime::fromMSecsSinceEpoch(
|
||||
qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY);
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
test.daysTo(other);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::msecsTo()
|
||||
{
|
||||
const QDateTime other = QDateTime::fromMSecsSinceEpoch(
|
||||
qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY);
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
test.msecsTo(other);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::equivalent()
|
||||
{
|
||||
bool result;
|
||||
const QDateTime other = QDateTime::fromMSecsSinceEpoch(
|
||||
qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY);
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
result = (test == other);
|
||||
}
|
||||
Q_UNUSED(result);
|
||||
}
|
||||
|
||||
void tst_QDateTime::equivalentUtc()
|
||||
{
|
||||
bool result = false;
|
||||
const QDateTime other = QDateTime::fromMSecsSinceEpoch(
|
||||
qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, QTimeZone::UTC);
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
result = (test == other);
|
||||
}
|
||||
Q_UNUSED(result);
|
||||
}
|
||||
|
||||
void tst_QDateTime::lessThan()
|
||||
{
|
||||
bool result = false;
|
||||
const QDateTime other = QDateTime::fromMSecsSinceEpoch(
|
||||
qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY);
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
result = (test < other);
|
||||
}
|
||||
Q_UNUSED(result);
|
||||
}
|
||||
|
||||
void tst_QDateTime::lessThanUtc()
|
||||
{
|
||||
bool result = false;
|
||||
const QDateTime other = QDateTime::fromMSecsSinceEpoch(
|
||||
qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, QTimeZone::UTC);
|
||||
const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
|
||||
QBENCHMARK {
|
||||
for (const QDateTime &test : list)
|
||||
result = (test < other);
|
||||
}
|
||||
Q_UNUSED(result);
|
||||
}
|
||||
|
||||
void tst_QDateTime::currentDateTime()
|
||||
{
|
||||
QBENCHMARK {
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
QDateTime::currentDateTime();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::currentDate()
|
||||
{
|
||||
QBENCHMARK {
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
QDate::currentDate();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::currentTime()
|
||||
{
|
||||
QBENCHMARK {
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
QTime::currentTime();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::currentDateTimeUtc()
|
||||
{
|
||||
QBENCHMARK {
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
QDateTime::currentDateTimeUtc();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::currentMSecsSinceEpoch()
|
||||
{
|
||||
QBENCHMARK {
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
QDateTime::currentMSecsSinceEpoch();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::fromString()
|
||||
{
|
||||
QString format = "yyyy-MM-dd hh:mm:ss.zzz";
|
||||
QString input = "2010-01-01 13:12:11.999";
|
||||
QVERIFY(QDateTime::fromString(input, format).isValid());
|
||||
QBENCHMARK {
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
QDateTime::fromString(input, format);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::fromStringText()
|
||||
{
|
||||
QString input = "Wed Jan 2 01:02:03.000 2013 GMT";
|
||||
QBENCHMARK {
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
QDateTime::fromString(input, Qt::TextDate);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::fromStringIso()
|
||||
{
|
||||
QString input = "2010-01-01T13:28:34.999Z";
|
||||
QBENCHMARK {
|
||||
for (int i = 0; i < 1000; ++i)
|
||||
QDateTime::fromString(input, Qt::ISODate);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::fromMSecsSinceEpoch()
|
||||
{
|
||||
const int start = JULIAN_DAY_2010 - JULIAN_DAY_1970;
|
||||
const int end = JULIAN_DAY_2020 - JULIAN_DAY_1970;
|
||||
QBENCHMARK {
|
||||
for (int jd = start; jd < end; ++jd)
|
||||
QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::fromMSecsSinceEpochUtc()
|
||||
{
|
||||
const int start = JULIAN_DAY_2010 - JULIAN_DAY_1970;
|
||||
const int end = JULIAN_DAY_2020 - JULIAN_DAY_1970;
|
||||
QBENCHMARK {
|
||||
for (int jd = start; jd < end; ++jd)
|
||||
QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, QTimeZone::UTC);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QDateTime::fromMSecsSinceEpochTz()
|
||||
{
|
||||
const int start = JULIAN_DAY_2010 - JULIAN_DAY_1970;
|
||||
const int end = JULIAN_DAY_2020 - JULIAN_DAY_1970;
|
||||
const QTimeZone cet("Europe/Oslo");
|
||||
QBENCHMARK {
|
||||
for (int jd = start; jd < end; ++jd)
|
||||
QDateTime test = QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, cet);
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QDateTime)
|
||||
|
||||
#include "tst_bench_qdatetime.moc"
|
13
tests/benchmarks/corelib/time/qtimezone/CMakeLists.txt
Normal file
13
tests/benchmarks/corelib/time/qtimezone/CMakeLists.txt
Normal file
@ -0,0 +1,13 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## tst_bench_qtimezone Binary:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_benchmark(tst_bench_qtimezone
|
||||
SOURCES
|
||||
tst_bench_qtimezone.cpp
|
||||
LIBRARIES
|
||||
Qt::Test
|
||||
)
|
148
tests/benchmarks/corelib/time/qtimezone/tst_bench_qtimezone.cpp
Normal file
148
tests/benchmarks/corelib/time/qtimezone/tst_bench_qtimezone.cpp
Normal file
@ -0,0 +1,148 @@
|
||||
// Copyright (C) 2019 Crimson AS <info@crimson.no>
|
||||
// Copyright (C) 2018 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author David Faure <david.faure@kdab.com>
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QTimeZone>
|
||||
#include <QTest>
|
||||
#include <qdebug.h>
|
||||
|
||||
// Enable to test *every* zone, rather than a hand-picked few, in some _data() sets:
|
||||
// #define EXHAUSTIVE
|
||||
|
||||
class tst_QTimeZone : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
void isTimeZoneIdAvailable();
|
||||
void systemTimeZone();
|
||||
void zoneByName_data();
|
||||
void zoneByName();
|
||||
void transitionList_data();
|
||||
void transitionList();
|
||||
void transitionsForward_data() { transitionList_data(); }
|
||||
void transitionsForward();
|
||||
void transitionsReverse_data() { transitionList_data(); }
|
||||
void transitionsReverse();
|
||||
};
|
||||
|
||||
static QList<QByteArray> enoughZones()
|
||||
{
|
||||
#ifdef EXHAUSTIVE
|
||||
auto available = QTimeZone::availableTimeZoneIds();
|
||||
QList<QByteArray> result;
|
||||
result.reserve(available.size() + 1);
|
||||
for (conat auto &name : available)
|
||||
result << name;
|
||||
#else
|
||||
QList<QByteArray> result {
|
||||
QByteArray("UTC"),
|
||||
// Those named overtly in tst_QDateTime - special cases first:
|
||||
QByteArray("UTC-02:00"), QByteArray("UTC+02:00"), QByteArray("UTC+12:00"),
|
||||
QByteArray("Etc/GMT+3"), QByteArray("GMT-2"), QByteArray("GMT"),
|
||||
// ... then ordinary names in alphabetic order:
|
||||
QByteArray("America/New_York"), QByteArray("America/Sao_Paulo"),
|
||||
QByteArray("America/Vancouver"),
|
||||
QByteArray("Asia/Kathmandu"), QByteArray("Asia/Singapore"),
|
||||
QByteArray("Australia/Brisbane"), QByteArray("Australia/Eucla"),
|
||||
QByteArray("Australia/Sydney"),
|
||||
QByteArray("Europe/Berlin"), QByteArray("Europe/Helsinki"),
|
||||
QByteArray("Europe/Rome"), QByteArray("Europe/Oslo"),
|
||||
QByteArray("Pacific/Apia"), QByteArray("Pacific/Auckland"),
|
||||
QByteArray("Pacific/Kiritimati")
|
||||
};
|
||||
#endif
|
||||
result << QByteArray("Vulcan/ShiKahr"); // invalid: also worth testing
|
||||
return result;
|
||||
}
|
||||
|
||||
void tst_QTimeZone::isTimeZoneIdAvailable()
|
||||
{
|
||||
const QList<QByteArray> available = QTimeZone::availableTimeZoneIds();
|
||||
QBENCHMARK {
|
||||
for (const QByteArray &id : available)
|
||||
QVERIFY(QTimeZone::isTimeZoneIdAvailable(id));
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QTimeZone::systemTimeZone()
|
||||
{
|
||||
QBENCHMARK {
|
||||
QTimeZone::systemTimeZone();
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QTimeZone::zoneByName_data()
|
||||
{
|
||||
QTest::addColumn<QByteArray>("name");
|
||||
|
||||
const auto names = enoughZones();
|
||||
for (const auto &name : names)
|
||||
QTest::newRow(name.constData()) << name;
|
||||
}
|
||||
|
||||
void tst_QTimeZone::zoneByName()
|
||||
{
|
||||
QFETCH(QByteArray, name);
|
||||
QTimeZone zone;
|
||||
QBENCHMARK {
|
||||
zone = QTimeZone(name);
|
||||
}
|
||||
Q_UNUSED(zone);
|
||||
}
|
||||
|
||||
void tst_QTimeZone::transitionList_data()
|
||||
{
|
||||
QTest::addColumn<QByteArray>("name");
|
||||
QTest::newRow("system") << QByteArray(); // Handled specially in the test.
|
||||
|
||||
const auto names = enoughZones();
|
||||
for (const auto &name : names) {
|
||||
QTimeZone zone(name);
|
||||
if (zone.isValid() && zone.hasTransitions())
|
||||
QTest::newRow(name.constData()) << name;
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QTimeZone::transitionList()
|
||||
{
|
||||
QFETCH(QByteArray, name);
|
||||
const QTimeZone zone = name.isEmpty() ? QTimeZone::systemTimeZone() : QTimeZone(name);
|
||||
const QDateTime early = QDate(1625, 6, 8).startOfDay(QTimeZone::UTC); // Cassini's birth date
|
||||
const QDateTime late // End of 32-bit signed time_t
|
||||
= QDateTime::fromSecsSinceEpoch(std::numeric_limits<qint32>::max(), QTimeZone::UTC);
|
||||
QTimeZone::OffsetDataList seq;
|
||||
QBENCHMARK {
|
||||
seq = zone.transitions(early, late);
|
||||
}
|
||||
Q_UNUSED(seq);
|
||||
}
|
||||
|
||||
void tst_QTimeZone::transitionsForward()
|
||||
{
|
||||
QFETCH(QByteArray, name);
|
||||
const QTimeZone zone = name.isEmpty() ? QTimeZone::systemTimeZone() : QTimeZone(name);
|
||||
const QDateTime early = QDate(1625, 6, 8).startOfDay(QTimeZone::UTC); // Cassini's birth date
|
||||
QBENCHMARK {
|
||||
QTimeZone::OffsetData tran = zone.nextTransition(early);
|
||||
while (tran.atUtc.isValid())
|
||||
tran = zone.nextTransition(tran.atUtc);
|
||||
}
|
||||
}
|
||||
|
||||
void tst_QTimeZone::transitionsReverse()
|
||||
{
|
||||
QFETCH(QByteArray, name);
|
||||
const QTimeZone zone = name.isEmpty() ? QTimeZone::systemTimeZone() : QTimeZone(name);
|
||||
const QDateTime late // End of 32-bit signed time_t
|
||||
= QDateTime::fromSecsSinceEpoch(std::numeric_limits<qint32>::max(), QTimeZone::UTC);
|
||||
QBENCHMARK {
|
||||
QTimeZone::OffsetData tran = zone.previousTransition(late);
|
||||
while (tran.atUtc.isValid())
|
||||
tran = zone.previousTransition(tran.atUtc);
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QTimeZone)
|
||||
|
||||
#include "tst_bench_qtimezone.moc"
|
Reference in New Issue
Block a user