summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/corelib
diff options
context:
space:
mode:
authorAlexandru Croitor <alexandru.croitor@qt.io>2019-09-04 14:33:40 +0200
committerAlexandru Croitor <alexandru.croitor@qt.io>2019-09-04 14:33:40 +0200
commitf255b1e8e297e7e1363921580007145cff574e0d (patch)
tree9a799be282e6c0d6544d9f8c872073f83e6c0475 /tests/benchmarks/corelib
parent7e8705f6632428a8d9a937ab5fe087999347b3dd (diff)
parentbf8fcab8bb92ff534c5cec048d6dbebb3b73a348 (diff)
Merge remote-tracking branch 'origin/dev' into wip/qt6
Diffstat (limited to 'tests/benchmarks/corelib')
-rw-r--r--tests/benchmarks/corelib/kernel/qobject/main.cpp47
-rw-r--r--tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp170
-rw-r--r--tests/benchmarks/corelib/time/qdatetime/main.cpp291
3 files changed, 344 insertions, 164 deletions
diff --git a/tests/benchmarks/corelib/kernel/qobject/main.cpp b/tests/benchmarks/corelib/kernel/qobject/main.cpp
index 04ca69ad3b..918227f74e 100644
--- a/tests/benchmarks/corelib/kernel/qobject/main.cpp
+++ b/tests/benchmarks/corelib/kernel/qobject/main.cpp
@@ -51,8 +51,55 @@ private slots:
void connect_disconnect_benchmark_data();
void connect_disconnect_benchmark();
void receiver_destroyed_benchmark();
+
+ void stdAllocator();
};
+class QObjectUsingStandardAllocator : public QObject
+{
+ Q_OBJECT
+public:
+ QObjectUsingStandardAllocator()
+ {
+ }
+};
+
+template<class T>
+inline void allocator()
+{
+ // We need to allocate certain amount of objects otherwise the new implementation
+ // may re-use the previous allocation, hiding the somehow high cost of allocation. It
+ // also helps us to reduce the noise ratio, which is high for memory allocation.
+ //
+ // The check depends on memory allocation performance, which is quite non-deterministic.
+ // When a new memory is requested, the new operator, depending on implementation, is trying
+ // to re-use existing, already allocated for the process memory. If there is not enough, it
+ // asks OS to give more. Of course the first case is faster then the second. In the same
+ // time, from an application perspective the first is also more likely.
+ //
+ // As a result, depending on which use-case one wants to test, it may be recommended to run this
+ // test in separation from others, to "force" expensive code path in the memory allocation.
+ //
+ // The time based results are heavily affected by background noise. One really needs to
+ // prepare OS (no other tasks, CPU and RAM reservations) to run this test, or use
+ // instruction counting which seems to be less fragile.
+
+ const int count = 256 * 1024;
+
+ QScopedPointer<T> objects[count];
+ QBENCHMARK_ONCE {
+ for (int i = 0; i < count; ++i)
+ objects[i].reset(new T);
+ for (int i = 0; i < count; ++i)
+ objects[i].reset();
+ }
+}
+
+void QObjectBenchmark::stdAllocator()
+{
+ allocator<QObjectUsingStandardAllocator>();
+}
+
struct Functor {
void operator()(){}
};
diff --git a/tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp b/tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp
index 399ac44065..10c013c080 100644
--- a/tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp
+++ b/tests/benchmarks/corelib/time/qdate/tst_bench_qdate.cpp
@@ -26,27 +26,187 @@
**
****************************************************************************/
-#include <QDateTime>
+#include <QDate>
#include <QTest>
+#include <QVector>
class tst_QDate : public QObject
{
Q_OBJECT
+ enum : qint64
+ {
+ JULIAN_DAY_2010 = 2455198,
+ JULIAN_DAY_2011 = 2455563,
+ JULIAN_DAY_2020 = 2458850,
+ };
+
+ static QVector<QDate> daily(qint64 start, qint64 end);
+ static QVector<QDate> yearly(qint32 first, qint32 last);
+
private Q_SLOTS:
- void monthLengths();
+ 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();
};
+QVector<QDate> tst_QDate::daily(qint64 start, qint64 end)
+{
+ QVector<QDate> list;
+ list.reserve(end - start);
+ for (qint64 jd = start; jd < end; ++jd)
+ list.append(QDate::fromJulianDay(jd));
+ return list;
+}
+
+QVector<QDate> tst_QDate::yearly(qint32 first, qint32 last)
+{
+ QVector<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++) {
- bool check = true;
for (int month = 1; month <= 12; month++)
- check &= QDate::isValid(year, month, QDate(year, month, 1).daysInMonth());
- Q_UNUSED(check);
+ 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)
diff --git a/tests/benchmarks/corelib/time/qdatetime/main.cpp b/tests/benchmarks/corelib/time/qdatetime/main.cpp
index b693400376..740e08cc46 100644
--- a/tests/benchmarks/corelib/time/qdatetime/main.cpp
+++ b/tests/benchmarks/corelib/time/qdatetime/main.cpp
@@ -29,6 +29,7 @@
#include <QDateTime>
#include <QTimeZone>
#include <QTest>
+#include <QVector>
#include <qdebug.h>
class tst_QDateTime : public QObject
@@ -41,6 +42,7 @@ class tst_QDateTime : public QObject
MSECS_PER_DAY = 86400000,
JULIAN_DAY_1950 = 2433283,
JULIAN_DAY_1960 = 2436935,
+ JULIAN_DAY_1970 = 2440588, // Epoch
JULIAN_DAY_2010 = 2455198,
JULIAN_DAY_2011 = 2455563,
JULIAN_DAY_2020 = 2458850,
@@ -48,6 +50,9 @@ class tst_QDateTime : public QObject
JULIAN_DAY_2060 = 2473460
};
+ static QVector<QDateTime> daily(qint64 start, qint64 end);
+ static QVector<QDateTime> norse(qint64 start, qint64 end);
+
private Q_SLOTS:
void create();
void isNull();
@@ -97,6 +102,25 @@ private Q_SLOTS:
void fromMSecsSinceEpochTz();
};
+QVector<QDateTime> tst_QDateTime::daily(qint64 start, qint64 end)
+{
+ QVector<QDateTime> list;
+ list.reserve(end - start);
+ for (int jd = start; jd < end; ++jd)
+ list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ return list;
+}
+
+QVector<QDateTime> tst_QDateTime::norse(qint64 start, qint64 end)
+{
+ const QTimeZone cet("Europe/Oslo");
+ QVector<QDateTime> list;
+ list.reserve(end - start);
+ for (int jd = start; jd < end; ++jd)
+ list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet));
+ return list;
+}
+
void tst_QDateTime::create()
{
QBENCHMARK {
@@ -109,339 +133,286 @@ void tst_QDateTime::create()
void tst_QDateTime::isNull()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
QBENCHMARK {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
test.isNull();
}
}
void tst_QDateTime::isValid()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
QBENCHMARK {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
test.isValid();
}
}
void tst_QDateTime::date()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
QBENCHMARK {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
test.date();
}
}
void tst_QDateTime::time()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
QBENCHMARK {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
test.time();
}
}
void tst_QDateTime::timeSpec()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
QBENCHMARK {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
test.timeSpec();
}
}
void tst_QDateTime::offsetFromUtc()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
QBENCHMARK {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
test.offsetFromUtc();
}
}
void tst_QDateTime::timeZoneAbbreviation()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
QBENCHMARK {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
test.timeZoneAbbreviation();
}
}
void tst_QDateTime::toMSecsSinceEpoch()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
QBENCHMARK {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
test.toMSecsSinceEpoch();
}
}
void tst_QDateTime::toMSecsSinceEpoch1950()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_1950; jd < JULIAN_DAY_1960; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_1950, JULIAN_DAY_1960);
QBENCHMARK {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
test.toMSecsSinceEpoch();
}
}
void tst_QDateTime::toMSecsSinceEpoch2050()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2050; jd < JULIAN_DAY_2060; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_2050, JULIAN_DAY_2060);
QBENCHMARK {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
test.toMSecsSinceEpoch();
}
}
void tst_QDateTime::toMSecsSinceEpochTz()
{
- QTimeZone cet = QTimeZone("Europe/Oslo");
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet));
+ qint64 result;
+ const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020);
QBENCHMARK {
- foreach (const QDateTime &test, list)
- qint64 result = test.toMSecsSinceEpoch();
+ for (const QDateTime &test : list)
+ result = test.toMSecsSinceEpoch();
}
+ Q_UNUSED(result);
}
void tst_QDateTime::toMSecsSinceEpoch1950Tz()
{
- QTimeZone cet = QTimeZone("Europe/Oslo");
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_1950; jd < JULIAN_DAY_1960; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet));
+ qint64 result;
+ const auto list = norse(JULIAN_DAY_1950, JULIAN_DAY_1960);
QBENCHMARK {
- foreach (const QDateTime &test, list)
- qint64 result = test.toMSecsSinceEpoch();
+ for (const QDateTime &test : list)
+ result = test.toMSecsSinceEpoch();
}
+ Q_UNUSED(result);
}
void tst_QDateTime::toMSecsSinceEpoch2050Tz()
{
- QTimeZone cet = QTimeZone("Europe/Oslo");
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2050; jd < JULIAN_DAY_2060; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet));
+ qint64 result;
+ const auto list = norse(JULIAN_DAY_2050, JULIAN_DAY_2060);
QBENCHMARK {
- foreach (const QDateTime &test, list)
- qint64 result = test.toMSecsSinceEpoch();
+ for (const QDateTime &test : list)
+ result = test.toMSecsSinceEpoch();
}
+ Q_UNUSED(result);
}
void tst_QDateTime::setDate()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
QBENCHMARK {
- foreach (QDateTime test, list)
+ for (QDateTime test : list)
test.setDate(QDate::fromJulianDay(JULIAN_DAY_2010));
}
}
void tst_QDateTime::setTime()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
QBENCHMARK {
- foreach (QDateTime test, list)
+ for (QDateTime test : list)
test.setTime(QTime(12, 0, 0));
}
}
void tst_QDateTime::setTimeSpec()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
QBENCHMARK {
- foreach (QDateTime test, list)
+ for (QDateTime test : list)
test.setTimeSpec(Qt::UTC);
}
}
void tst_QDateTime::setOffsetFromUtc()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
QBENCHMARK {
- foreach (QDateTime test, list)
+ for (QDateTime test : list)
test.setOffsetFromUtc(3600);
}
}
void tst_QDateTime::setMSecsSinceEpoch()
{
- qint64 msecs = qint64(JULIAN_DAY_2010 + 180) * MSECS_PER_DAY;
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ qint64 msecs = qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970 + 180) * MSECS_PER_DAY;
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
QBENCHMARK {
- foreach (QDateTime test, list)
+ for (QDateTime test : list)
test.setMSecsSinceEpoch(msecs);
}
}
void tst_QDateTime::setMSecsSinceEpochTz()
{
- QTimeZone cet = QTimeZone("Europe/Oslo");
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet));
+ 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 {
- foreach (QDateTime test, list)
- test.setMSecsSinceEpoch((JULIAN_DAY_2010 + 180) * MSECS_PER_DAY);
+ for (QDateTime test : list)
+ test.setMSecsSinceEpoch(msecs);
}
}
void tst_QDateTime::toString()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2011; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2011);
QBENCHMARK {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
test.toString(QStringLiteral("yyy-MM-dd hh:mm:ss.zzz t"));
}
}
void tst_QDateTime::toStringTextFormat()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2011; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2011);
QBENCHMARK {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
test.toString(Qt::TextDate);
}
}
void tst_QDateTime::toStringIsoFormat()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2011; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2011);
QBENCHMARK {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
test.toString(Qt::ISODate);
}
}
void tst_QDateTime::addDays()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
+ QDateTime next;
QBENCHMARK {
- foreach (const QDateTime &test, list)
- test.addDays(1);
+ for (const QDateTime &test : list)
+ next = test.addDays(1);
}
+ Q_UNUSED(next);
}
void tst_QDateTime::addDaysTz()
{
- QTimeZone cet = QTimeZone("Europe/Oslo");
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet));
+ const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020);
QBENCHMARK {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
QDateTime result = test.addDays(1);
}
}
void tst_QDateTime::addMSecs()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
+ QDateTime next;
QBENCHMARK {
- foreach (const QDateTime &test, list)
- test.addMSecs(1);
+ for (const QDateTime &test : list)
+ next = test.addMSecs(1);
}
+ Q_UNUSED(next);
}
void tst_QDateTime::addMSecsTz()
{
- QTimeZone cet = QTimeZone("Europe/Oslo");
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet));
+ const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020);
QBENCHMARK {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
QDateTime result = test.addMSecs(1);
}
}
void tst_QDateTime::toTimeSpec()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
QBENCHMARK {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
test.toTimeSpec(Qt::UTC);
}
}
void tst_QDateTime::toOffsetFromUtc()
{
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
QBENCHMARK {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
test.toOffsetFromUtc(3600);
}
}
void tst_QDateTime::daysTo()
{
- QDateTime other = QDateTime::fromMSecsSinceEpoch(qint64(JULIAN_DAY_2010) * MSECS_PER_DAY);
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ 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 {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
test.daysTo(other);
}
}
void tst_QDateTime::msecsTo()
{
- QDateTime other = QDateTime::fromMSecsSinceEpoch(qint64(JULIAN_DAY_2010) * MSECS_PER_DAY);
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ 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 {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
test.msecsTo(other);
}
}
@@ -449,12 +420,11 @@ void tst_QDateTime::msecsTo()
void tst_QDateTime::equivalent()
{
bool result;
- QDateTime other = QDateTime::fromMSecsSinceEpoch(qint64(JULIAN_DAY_2010) * MSECS_PER_DAY);
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ 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 {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
result = (test == other);
}
Q_UNUSED(result)
@@ -463,12 +433,11 @@ void tst_QDateTime::equivalent()
void tst_QDateTime::equivalentUtc()
{
bool result = false;
- QDateTime other = QDateTime::fromMSecsSinceEpoch(qint64(JULIAN_DAY_2010) * MSECS_PER_DAY, Qt::UTC);
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const QDateTime other = QDateTime::fromMSecsSinceEpoch(
+ qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, Qt::UTC);
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
QBENCHMARK {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
result = (test == other);
}
Q_UNUSED(result)
@@ -477,12 +446,11 @@ void tst_QDateTime::equivalentUtc()
void tst_QDateTime::lessThan()
{
bool result = false;
- QDateTime other = QDateTime::fromMSecsSinceEpoch(qint64(JULIAN_DAY_2010) * MSECS_PER_DAY);
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ 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 {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
result = (test < other);
}
Q_UNUSED(result)
@@ -491,12 +459,11 @@ void tst_QDateTime::lessThan()
void tst_QDateTime::lessThanUtc()
{
bool result = false;
- QDateTime other = QDateTime::fromMSecsSinceEpoch(qint64(JULIAN_DAY_2010) * MSECS_PER_DAY, Qt::UTC);
- QList<QDateTime> list;
- for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
- list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
+ const QDateTime other = QDateTime::fromMSecsSinceEpoch(
+ qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, Qt::UTC);
+ const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020);
QBENCHMARK {
- foreach (const QDateTime &test, list)
+ for (const QDateTime &test : list)
result = (test < other);
}
Q_UNUSED(result)
@@ -573,25 +540,31 @@ void tst_QDateTime::fromStringIso()
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 = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
+ for (int jd = start; jd < end; ++jd)
QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, Qt::LocalTime);
}
}
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 = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
+ for (int jd = start; jd < end; ++jd)
QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, Qt::UTC);
}
}
void tst_QDateTime::fromMSecsSinceEpochTz()
{
- QTimeZone cet = QTimeZone("Europe/Oslo");
+ 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 = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd)
+ for (int jd = start; jd < end; ++jd)
QDateTime test = QDateTime::fromMSecsSinceEpoch(jd * MSECS_PER_DAY, cet);
}
}