From 2cddaf0071d647221ea4936da22bca86cd523799 Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Mon, 19 Aug 2019 14:46:28 +0200 Subject: Fix tst_bench_qimagereader It couldn't find the test images if not build in sources. Change-Id: Ieeb5a76694a37d05b3e9a4ed0154885040b0812f Reviewed-by: Daniel Smith Reviewed-by: Eirik Aavitsland --- .../benchmarks/gui/image/qimagereader/qimagereader.pro | 2 ++ .../gui/image/qimagereader/tst_qimagereader.cpp | 17 +++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) (limited to 'tests/benchmarks') diff --git a/tests/benchmarks/gui/image/qimagereader/qimagereader.pro b/tests/benchmarks/gui/image/qimagereader/qimagereader.pro index 29f7f6b16e..3454cf1474 100644 --- a/tests/benchmarks/gui/image/qimagereader/qimagereader.pro +++ b/tests/benchmarks/gui/image/qimagereader/qimagereader.pro @@ -8,3 +8,5 @@ SOURCES += tst_qimagereader.cpp qtConfig(gif): DEFINES += QTEST_HAVE_GIF qtConfig(jpeg): DEFINES += QTEST_HAVE_JPEG + +TESTDATA += images/* diff --git a/tests/benchmarks/gui/image/qimagereader/tst_qimagereader.cpp b/tests/benchmarks/gui/image/qimagereader/tst_qimagereader.cpp index d81d5bb01a..48e838148f 100644 --- a/tests/benchmarks/gui/image/qimagereader/tst_qimagereader.cpp +++ b/tests/benchmarks/gui/image/qimagereader/tst_qimagereader.cpp @@ -51,6 +51,7 @@ public: virtual ~tst_QImageReader(); public slots: + void initTestCase(); void init(); void cleanup(); @@ -69,6 +70,7 @@ private slots: private: QList< QPair > images; // filename, format + QString prefix; }; tst_QImageReader::tst_QImageReader() @@ -102,6 +104,13 @@ tst_QImageReader::~tst_QImageReader() { } +void tst_QImageReader::initTestCase() +{ + prefix = QFINDTESTDATA("images/"); + if (prefix.isEmpty()) + QFAIL("Can't find images directory!"); +} + void tst_QImageReader::init() { } @@ -128,7 +137,7 @@ void tst_QImageReader::readImage() QFETCH(QByteArray, format); QBENCHMARK { - QImageReader io("images/" + fileName, format); + QImageReader io(prefix + fileName, format); QImage image = io.read(); QVERIFY(!image.isNull()); } @@ -159,7 +168,7 @@ void tst_QImageReader::setScaledSize() QFETCH(QByteArray, format); QBENCHMARK { - QImageReader reader("images/" + fileName, format); + QImageReader reader(prefix + fileName, format); reader.setScaledSize(newSize); QImage image = reader.read(); QCOMPARE(image.size(), newSize); @@ -186,7 +195,7 @@ void tst_QImageReader::setClipRect() QFETCH(QByteArray, format); QBENCHMARK { - QImageReader reader("images/" + fileName, format); + QImageReader reader(prefix + fileName, format); reader.setClipRect(newRect); QImage image = reader.read(); QCOMPARE(image.rect(), newRect); @@ -205,7 +214,7 @@ void tst_QImageReader::setScaledClipRect() QFETCH(QByteArray, format); QBENCHMARK { - QImageReader reader("images/" + fileName, format); + QImageReader reader(prefix + fileName, format); reader.setScaledSize(QSize(300, 300)); reader.setScaledClipRect(newRect); QImage image = reader.read(); -- cgit v1.2.3 From ce73b4db62574fc966192e6a4f65b7e2b2280e38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 20 Aug 2019 14:26:05 +0200 Subject: Remove dead code from Qt 4 times MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The benefit of keeping this code around was to inspire or inform changes in the areas to take into account possibly missing features in Qt 5, but at this point that benefit is questionable. We can always use the history to learn about missing pieces if needed. Change-Id: I87a02dc451e9027be9b97554427bf8a1c6b2c025 Reviewed-by: Tor Arne Vestbø --- .../graphicsview/qgraphicsview/benchapps/chipTest/view.cpp | 5 ----- .../graphicsview/qgraphicsview/benchapps/moveItems/main.cpp | 12 ------------ .../graphicsview/qgraphicsview/benchapps/scrolltest/main.cpp | 5 ----- 3 files changed, 22 deletions(-) (limited to 'tests/benchmarks') diff --git a/tests/benchmarks/widgets/graphicsview/qgraphicsview/benchapps/chipTest/view.cpp b/tests/benchmarks/widgets/graphicsview/qgraphicsview/benchapps/chipTest/view.cpp index de4e9e5ad7..6e0ac445a6 100644 --- a/tests/benchmarks/widgets/graphicsview/qgraphicsview/benchapps/chipTest/view.cpp +++ b/tests/benchmarks/widgets/graphicsview/qgraphicsview/benchapps/chipTest/view.cpp @@ -30,12 +30,7 @@ #include -#if 0 // Used to be included in Qt4 for Q_WS_WIN -#define CALLGRIND_START_INSTRUMENTATION {} -#define CALLGRIND_STOP_INSTRUMENTATION {} -#else #include "valgrind/callgrind.h" -#endif #ifndef QT_NO_OPENGL #include diff --git a/tests/benchmarks/widgets/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp b/tests/benchmarks/widgets/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp index e0cc0f8eb4..140278b8f6 100644 --- a/tests/benchmarks/widgets/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp +++ b/tests/benchmarks/widgets/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp @@ -27,16 +27,7 @@ ****************************************************************************/ #include -#if 0 // Used to be included in Qt4 for Q_WS_WIN -#define CALLGRIND_START_INSTRUMENTATION {} -#define CALLGRIND_STOP_INSTRUMENTATION {} -#else #include "valgrind/callgrind.h" -#endif - -#if 0 // Used to be included in Qt4 for Q_WS_X11 -extern void qt_x11_wait_for_window_manager(QWidget *); -#endif class View : public QGraphicsView { @@ -89,9 +80,6 @@ int main(int argc, char *argv[]) View view(&scene, item); view.resize(300, 300); view.show(); -#if 0 // Used to be included in Qt4 for Q_WS_X11 - qt_x11_wait_for_window_manager(&view); -#endif return app.exec(); } diff --git a/tests/benchmarks/widgets/graphicsview/qgraphicsview/benchapps/scrolltest/main.cpp b/tests/benchmarks/widgets/graphicsview/qgraphicsview/benchapps/scrolltest/main.cpp index 1fbb229cd8..566d16ca51 100644 --- a/tests/benchmarks/widgets/graphicsview/qgraphicsview/benchapps/scrolltest/main.cpp +++ b/tests/benchmarks/widgets/graphicsview/qgraphicsview/benchapps/scrolltest/main.cpp @@ -27,12 +27,7 @@ ****************************************************************************/ #include -#if 0 // Used to be included in Qt4 for Q_WS_WIN -#define CALLGRIND_START_INSTRUMENTATION {} -#define CALLGRIND_STOP_INSTRUMENTATION {} -#else #include "valgrind/callgrind.h" -#endif class ItemMover : public QObject { -- cgit v1.2.3 From 5d94aac2bae8bdbf8de7cebeb6a1a17a81685f0a Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Thu, 4 Jul 2019 15:17:29 +0200 Subject: Introduce QImage::Format_BGR888 Is pretty common on some architectures so we can avoid swizzling by supporting it. Fixes: QTBUG-45671 Change-Id: Ic7a21b5bfb374bf7496fd2b2b1252c2f1ed47705 Reviewed-by: Eirik Aavitsland --- .../qimageconversion/tst_qimageconversion.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'tests/benchmarks') diff --git a/tests/benchmarks/gui/image/qimageconversion/tst_qimageconversion.cpp b/tests/benchmarks/gui/image/qimageconversion/tst_qimageconversion.cpp index 570c7b59fa..b88669e9ce 100644 --- a/tests/benchmarks/gui/image/qimageconversion/tst_qimageconversion.cpp +++ b/tests/benchmarks/gui/image/qimageconversion/tst_qimageconversion.cpp @@ -183,6 +183,7 @@ void tst_QImageConversion::convertRgb32_data() QTest::newRow("rgb32 -> rgb30") << rgb32 << QImage::Format_RGB30; QTest::newRow("rgb32 -> a2bgr30") << rgb32 << QImage::Format_A2BGR30_Premultiplied; QTest::newRow("rgb32 -> rgb888") << rgb32 << QImage::Format_RGB888; + QTest::newRow("rgb32 -> bgr888") << rgb32 << QImage::Format_BGR888; QTest::newRow("rgb32 -> rgb666") << rgb32 << QImage::Format_RGB666; QTest::newRow("rgb32 -> rgb555") << rgb32 << QImage::Format_RGB555; QTest::newRow("rgb32 -> argb8565pm") << rgb32 << QImage::Format_ARGB8565_Premultiplied; @@ -196,6 +197,7 @@ void tst_QImageConversion::convertRgb32_data() QTest::newRow("argb32 -> rgb30") << argb32 << QImage::Format_RGB30; QTest::newRow("argb32 -> a2bgr30") << argb32 << QImage::Format_A2BGR30_Premultiplied; QTest::newRow("argb32 -> rgb888") << argb32 << QImage::Format_RGB888; + QTest::newRow("argb32 -> bgr888") << argb32 << QImage::Format_BGR888; QTest::newRow("argb32 -> rgb666") << argb32 << QImage::Format_RGB666; QTest::newRow("argb32 -> argb8565pm") << argb32 << QImage::Format_ARGB8565_Premultiplied; QTest::newRow("argb32 -> argb4444pm") << argb32 << QImage::Format_ARGB4444_Premultiplied; @@ -212,6 +214,7 @@ void tst_QImageConversion::convertRgb32_data() QTest::newRow("argb32pm -> rgb30") << argb32pm << QImage::Format_RGB30; QTest::newRow("argb32pm -> a2bgr30") << argb32pm << QImage::Format_A2BGR30_Premultiplied; QTest::newRow("argb32pm -> rgb888") << argb32pm << QImage::Format_RGB888; + QTest::newRow("argb32pm -> bgr888") << argb32pm << QImage::Format_BGR888; QTest::newRow("argb32pm -> rgb666") << argb32pm << QImage::Format_RGB666; QTest::newRow("argb32pm -> argb8565pm") << argb32pm << QImage::Format_ARGB8565_Premultiplied; QTest::newRow("argb32pm -> argb4444pm") << argb32pm << QImage::Format_ARGB4444_Premultiplied; @@ -242,6 +245,8 @@ void tst_QImageConversion::convertGeneric_data() QImage rgb666 = rgb32.convertToFormat(QImage::Format_RGB666); QImage argb4444 = argb32.convertToFormat(QImage::Format_ARGB4444_Premultiplied); QImage rgba64pm = argb32.convertToFormat(QImage::Format_RGBA64_Premultiplied); + QImage rgb888 = rgb32.convertToFormat(QImage::Format_RGB888); + QImage bgr888 = rgb32.convertToFormat(QImage::Format_BGR888); QTest::newRow("indexed8 -> rgb32") << i8 << QImage::Format_RGB32; QTest::newRow("indexed8 -> argb32") << i8 << QImage::Format_ARGB32; @@ -299,6 +304,20 @@ void tst_QImageConversion::convertGeneric_data() QTest::newRow("rgba64pm -> rgb30") << rgba64pm << QImage::Format_RGB30; QTest::newRow("rgba64pm -> a2bgr30") << rgba64pm << QImage::Format_A2BGR30_Premultiplied; QTest::newRow("rgba64pm -> rgba64") << rgba64pm << QImage::Format_RGBA64; + + QTest::newRow("rgb888 -> rgb32") << rgb888 << QImage::Format_RGB32; + QTest::newRow("rgb888 -> argb32") << rgb888 << QImage::Format_ARGB32; + QTest::newRow("rgb888 -> argb32pm") << rgb888 << QImage::Format_ARGB32_Premultiplied; + QTest::newRow("rgb888 -> rgbx8888") << rgb888 << QImage::Format_RGBX8888; + QTest::newRow("rgb888 -> rgba8888pm") << rgb888 << QImage::Format_RGBA8888_Premultiplied; + QTest::newRow("rgb888 -> bgr888") << rgb888 << QImage::Format_BGR888; + + QTest::newRow("bgr888 -> rgb32") << bgr888 << QImage::Format_RGB32; + QTest::newRow("bgr888 -> argb32") << bgr888 << QImage::Format_ARGB32; + QTest::newRow("bgr888 -> argb32pm") << bgr888 << QImage::Format_ARGB32_Premultiplied; + QTest::newRow("bgr888 -> rgbx8888") << bgr888 << QImage::Format_RGBX8888; + QTest::newRow("bgr888 -> rgba8888pm") << bgr888 << QImage::Format_RGBA8888_Premultiplied; + QTest::newRow("bgr888 -> rgb888") << bgr888 << QImage::Format_RGB888; } void tst_QImageConversion::convertGeneric() @@ -323,6 +342,7 @@ void tst_QImageConversion::convertGenericInplace_data() QImage argb6666 = argb32.convertToFormat(QImage::Format_ARGB6666_Premultiplied); QImage argb4444 = argb32.convertToFormat(QImage::Format_ARGB4444_Premultiplied); QImage rgb16 = argb32.convertToFormat(QImage::Format_RGB16); + QImage rgb888 = argb32.convertToFormat(QImage::Format_RGB888); QTest::newRow("argb32 -> argb32pm -> argb32") << argb32 << QImage::Format_ARGB32_Premultiplied; QTest::newRow("argb32 -> rgb32 -> argb32") << argb32 << QImage::Format_RGB32; @@ -349,6 +369,8 @@ void tst_QImageConversion::convertGenericInplace_data() QTest::newRow("rgb16 -> rgb555 -> rgb16") << rgb16 << QImage::Format_RGB555; QTest::newRow("rgb16 -> rgb444 -> rgb16") << rgb16 << QImage::Format_RGB444; QTest::newRow("rgb16 -> argb4444pm -> rgb16") << rgb16 << QImage::Format_ARGB4444_Premultiplied; + + QTest::newRow("rgb888 -> bgr888 -> rgb888") << rgb888 << QImage::Format_BGR888; } void tst_QImageConversion::convertGenericInplace() -- cgit v1.2.3 From 949482f8e43533d3370201c0f216253c7b5872bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Tue, 26 Feb 2019 09:31:18 +0100 Subject: Add QObject allocation benchmarks The benchmark measures the performance of QObject allocation, including costs of memory allocations. Change-Id: I5d8ecfb97fe0be3375340b5ce84eb423e8a4ddaf Reviewed-by: Volker Hilsheimer --- tests/benchmarks/corelib/kernel/qobject/main.cpp | 47 ++++++++++++++++++++++++ 1 file changed, 47 insertions(+) (limited to 'tests/benchmarks') 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 +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 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(); +} + struct Functor { void operator()(){} }; -- cgit v1.2.3 From 06f69700af0bb312f08f9455f127abf452896d48 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 29 Aug 2019 13:41:17 +0200 Subject: Fix some bogus date calculations in QDateTime's benchmark Multiplying a Julian Day number by the number of milliseconds per day does not get you a time since the start of 1970; it gets you a time since the start of the Julian Day number system, which was several millennia earlier. Change-Id: Ic90a6c3de445baf9cfd30f28dd847f146e6a7adf Reviewed-by: David Faure --- tests/benchmarks/corelib/time/qdatetime/main.cpp | 38 ++++++++++++++++-------- 1 file changed, 26 insertions(+), 12 deletions(-) (limited to 'tests/benchmarks') diff --git a/tests/benchmarks/corelib/time/qdatetime/main.cpp b/tests/benchmarks/corelib/time/qdatetime/main.cpp index b693400376..728c4acb91 100644 --- a/tests/benchmarks/corelib/time/qdatetime/main.cpp +++ b/tests/benchmarks/corelib/time/qdatetime/main.cpp @@ -41,6 +41,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, @@ -299,7 +300,7 @@ void tst_QDateTime::setOffsetFromUtc() void tst_QDateTime::setMSecsSinceEpoch() { - qint64 msecs = qint64(JULIAN_DAY_2010 + 180) * MSECS_PER_DAY; + qint64 msecs = qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970 + 180) * MSECS_PER_DAY; QList list; for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); @@ -313,11 +314,12 @@ void tst_QDateTime::setMSecsSinceEpochTz() { QTimeZone cet = QTimeZone("Europe/Oslo"); QList list; + const qint64 msecs = qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970 + 180) * MSECS_PER_DAY; for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet)); QBENCHMARK { foreach (QDateTime test, list) - test.setMSecsSinceEpoch((JULIAN_DAY_2010 + 180) * MSECS_PER_DAY); + test.setMSecsSinceEpoch(msecs); } } @@ -424,7 +426,8 @@ void tst_QDateTime::toOffsetFromUtc() void tst_QDateTime::daysTo() { - QDateTime other = QDateTime::fromMSecsSinceEpoch(qint64(JULIAN_DAY_2010) * MSECS_PER_DAY); + const QDateTime other = QDateTime::fromMSecsSinceEpoch( + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY); QList list; for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); @@ -436,7 +439,8 @@ void tst_QDateTime::daysTo() void tst_QDateTime::msecsTo() { - QDateTime other = QDateTime::fromMSecsSinceEpoch(qint64(JULIAN_DAY_2010) * MSECS_PER_DAY); + const QDateTime other = QDateTime::fromMSecsSinceEpoch( + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY); QList list; for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); @@ -449,7 +453,8 @@ void tst_QDateTime::msecsTo() void tst_QDateTime::equivalent() { bool result; - QDateTime other = QDateTime::fromMSecsSinceEpoch(qint64(JULIAN_DAY_2010) * MSECS_PER_DAY); + const QDateTime other = QDateTime::fromMSecsSinceEpoch( + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY); QList list; for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); @@ -463,7 +468,8 @@ void tst_QDateTime::equivalent() void tst_QDateTime::equivalentUtc() { bool result = false; - QDateTime other = QDateTime::fromMSecsSinceEpoch(qint64(JULIAN_DAY_2010) * MSECS_PER_DAY, Qt::UTC); + const QDateTime other = QDateTime::fromMSecsSinceEpoch( + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, Qt::UTC); QList list; for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); @@ -477,7 +483,8 @@ void tst_QDateTime::equivalentUtc() void tst_QDateTime::lessThan() { bool result = false; - QDateTime other = QDateTime::fromMSecsSinceEpoch(qint64(JULIAN_DAY_2010) * MSECS_PER_DAY); + const QDateTime other = QDateTime::fromMSecsSinceEpoch( + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY); QList list; for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); @@ -491,7 +498,8 @@ void tst_QDateTime::lessThan() void tst_QDateTime::lessThanUtc() { bool result = false; - QDateTime other = QDateTime::fromMSecsSinceEpoch(qint64(JULIAN_DAY_2010) * MSECS_PER_DAY, Qt::UTC); + const QDateTime other = QDateTime::fromMSecsSinceEpoch( + qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, Qt::UTC); QList list; for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); @@ -573,25 +581,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); } } -- cgit v1.2.3 From 54f6c9bfd900fbee8800d720879ecb0c023585ac Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 29 Aug 2019 14:05:48 +0200 Subject: Fix unused variable warnings in QDateTime benchmark Change-Id: Id123ace74cfa7b5ff406eabbfda0aad9f58c3fd4 Reviewed-by: David Faure --- tests/benchmarks/corelib/time/qdatetime/main.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'tests/benchmarks') diff --git a/tests/benchmarks/corelib/time/qdatetime/main.cpp b/tests/benchmarks/corelib/time/qdatetime/main.cpp index 728c4acb91..e616181bea 100644 --- a/tests/benchmarks/corelib/time/qdatetime/main.cpp +++ b/tests/benchmarks/corelib/time/qdatetime/main.cpp @@ -221,37 +221,43 @@ void tst_QDateTime::toMSecsSinceEpoch2050() void tst_QDateTime::toMSecsSinceEpochTz() { QTimeZone cet = QTimeZone("Europe/Oslo"); + qint64 result; QList list; for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet)); QBENCHMARK { foreach (const QDateTime &test, list) - qint64 result = test.toMSecsSinceEpoch(); + result = test.toMSecsSinceEpoch(); } + Q_UNUSED(result); } void tst_QDateTime::toMSecsSinceEpoch1950Tz() { QTimeZone cet = QTimeZone("Europe/Oslo"); + qint64 result; QList list; for (int jd = JULIAN_DAY_1950; jd < JULIAN_DAY_1960; ++jd) list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet)); QBENCHMARK { foreach (const QDateTime &test, list) - qint64 result = test.toMSecsSinceEpoch(); + result = test.toMSecsSinceEpoch(); } + Q_UNUSED(result); } void tst_QDateTime::toMSecsSinceEpoch2050Tz() { QTimeZone cet = QTimeZone("Europe/Oslo"); + qint64 result; QList list; for (int jd = JULIAN_DAY_2050; jd < JULIAN_DAY_2060; ++jd) list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet)); QBENCHMARK { foreach (const QDateTime &test, list) - qint64 result = test.toMSecsSinceEpoch(); + result = test.toMSecsSinceEpoch(); } + Q_UNUSED(result); } void tst_QDateTime::setDate() @@ -359,12 +365,14 @@ void tst_QDateTime::toStringIsoFormat() void tst_QDateTime::addDays() { QList list; + QDateTime next; for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); QBENCHMARK { foreach (const QDateTime &test, list) - test.addDays(1); + next = test.addDays(1); } + Q_UNUSED(next); } void tst_QDateTime::addDaysTz() @@ -382,12 +390,14 @@ void tst_QDateTime::addDaysTz() void tst_QDateTime::addMSecs() { QList list; + QDateTime next; for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); QBENCHMARK { foreach (const QDateTime &test, list) - test.addMSecs(1); + next = test.addMSecs(1); } + Q_UNUSED(next); } void tst_QDateTime::addMSecsTz() -- cgit v1.2.3 From 0556366ddb3a59071256a5646c3c82e7da23d619 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 29 Aug 2019 15:24:52 +0200 Subject: Deduplicate list-building code in QDateTime benchmark Aside from the start-date and the end-date, and a variant with a time-zone, the lists various tests were building were all built the same way; so pack that up as a pair of functions (one without time-zone, one with) to save duplication. Make the list in each function const, ready for conversion of foreach loops to ranged for. In the process, replace QList with QVector, reserve space before we populate and use auto for the now-const list variables it's saved in. Change-Id: I7d8cce459a4d6111cd645e8d3966ad769ab7e201 Reviewed-by: Marc Mutz --- tests/benchmarks/corelib/time/qdatetime/main.cpp | 165 ++++++++--------------- 1 file changed, 57 insertions(+), 108 deletions(-) (limited to 'tests/benchmarks') diff --git a/tests/benchmarks/corelib/time/qdatetime/main.cpp b/tests/benchmarks/corelib/time/qdatetime/main.cpp index e616181bea..2730e7e18b 100644 --- a/tests/benchmarks/corelib/time/qdatetime/main.cpp +++ b/tests/benchmarks/corelib/time/qdatetime/main.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include class tst_QDateTime : public QObject @@ -49,6 +50,9 @@ class tst_QDateTime : public QObject JULIAN_DAY_2060 = 2473460 }; + static QVector daily(qint64 start, qint64 end); + static QVector norse(qint64 start, qint64 end); + private Q_SLOTS: void create(); void isNull(); @@ -98,6 +102,25 @@ private Q_SLOTS: void fromMSecsSinceEpochTz(); }; +QVector tst_QDateTime::daily(qint64 start, qint64 end) +{ + QVector list; + list.reserve(end - start); + for (int jd = start; jd < end; ++jd) + list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); + return list; +} + +QVector tst_QDateTime::norse(qint64 start, qint64 end) +{ + const QTimeZone cet("Europe/Oslo"); + QVector 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 { @@ -110,9 +133,7 @@ void tst_QDateTime::create() void tst_QDateTime::isNull() { - QList 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) test.isNull(); @@ -121,9 +142,7 @@ void tst_QDateTime::isNull() void tst_QDateTime::isValid() { - QList 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) test.isValid(); @@ -132,9 +151,7 @@ void tst_QDateTime::isValid() void tst_QDateTime::date() { - QList 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) test.date(); @@ -143,9 +160,7 @@ void tst_QDateTime::date() void tst_QDateTime::time() { - QList 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) test.time(); @@ -154,9 +169,7 @@ void tst_QDateTime::time() void tst_QDateTime::timeSpec() { - QList 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) test.timeSpec(); @@ -165,9 +178,7 @@ void tst_QDateTime::timeSpec() void tst_QDateTime::offsetFromUtc() { - QList 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) test.offsetFromUtc(); @@ -176,9 +187,7 @@ void tst_QDateTime::offsetFromUtc() void tst_QDateTime::timeZoneAbbreviation() { - QList 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) test.timeZoneAbbreviation(); @@ -187,9 +196,7 @@ void tst_QDateTime::timeZoneAbbreviation() void tst_QDateTime::toMSecsSinceEpoch() { - QList 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) test.toMSecsSinceEpoch(); @@ -198,9 +205,7 @@ void tst_QDateTime::toMSecsSinceEpoch() void tst_QDateTime::toMSecsSinceEpoch1950() { - QList 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) test.toMSecsSinceEpoch(); @@ -209,9 +214,7 @@ void tst_QDateTime::toMSecsSinceEpoch1950() void tst_QDateTime::toMSecsSinceEpoch2050() { - QList 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) test.toMSecsSinceEpoch(); @@ -220,11 +223,8 @@ void tst_QDateTime::toMSecsSinceEpoch2050() void tst_QDateTime::toMSecsSinceEpochTz() { - QTimeZone cet = QTimeZone("Europe/Oslo"); qint64 result; - QList 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) result = test.toMSecsSinceEpoch(); @@ -234,11 +234,8 @@ void tst_QDateTime::toMSecsSinceEpochTz() void tst_QDateTime::toMSecsSinceEpoch1950Tz() { - QTimeZone cet = QTimeZone("Europe/Oslo"); qint64 result; - QList list; - for (int jd = JULIAN_DAY_1950; jd < JULIAN_DAY_1960; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet)); + const auto list = norse(JULIAN_DAY_1950, JULIAN_DAY_1960); QBENCHMARK { foreach (const QDateTime &test, list) result = test.toMSecsSinceEpoch(); @@ -248,11 +245,8 @@ void tst_QDateTime::toMSecsSinceEpoch1950Tz() void tst_QDateTime::toMSecsSinceEpoch2050Tz() { - QTimeZone cet = QTimeZone("Europe/Oslo"); qint64 result; - QList list; - for (int jd = JULIAN_DAY_2050; jd < JULIAN_DAY_2060; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet)); + const auto list = norse(JULIAN_DAY_2050, JULIAN_DAY_2060); QBENCHMARK { foreach (const QDateTime &test, list) result = test.toMSecsSinceEpoch(); @@ -262,9 +256,7 @@ void tst_QDateTime::toMSecsSinceEpoch2050Tz() void tst_QDateTime::setDate() { - QList 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) test.setDate(QDate::fromJulianDay(JULIAN_DAY_2010)); @@ -273,9 +265,7 @@ void tst_QDateTime::setDate() void tst_QDateTime::setTime() { - QList 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) test.setTime(QTime(12, 0, 0)); @@ -284,9 +274,7 @@ void tst_QDateTime::setTime() void tst_QDateTime::setTimeSpec() { - QList 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) test.setTimeSpec(Qt::UTC); @@ -295,9 +283,7 @@ void tst_QDateTime::setTimeSpec() void tst_QDateTime::setOffsetFromUtc() { - QList 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) test.setOffsetFromUtc(3600); @@ -307,9 +293,7 @@ void tst_QDateTime::setOffsetFromUtc() void tst_QDateTime::setMSecsSinceEpoch() { qint64 msecs = qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970 + 180) * MSECS_PER_DAY; - QList 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) test.setMSecsSinceEpoch(msecs); @@ -318,11 +302,8 @@ void tst_QDateTime::setMSecsSinceEpoch() void tst_QDateTime::setMSecsSinceEpochTz() { - QTimeZone cet = QTimeZone("Europe/Oslo"); - QList list; const qint64 msecs = qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970 + 180) * MSECS_PER_DAY; - 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 (QDateTime test, list) test.setMSecsSinceEpoch(msecs); @@ -331,9 +312,7 @@ void tst_QDateTime::setMSecsSinceEpochTz() void tst_QDateTime::toString() { - QList 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) test.toString(QStringLiteral("yyy-MM-dd hh:mm:ss.zzz t")); @@ -342,9 +321,7 @@ void tst_QDateTime::toString() void tst_QDateTime::toStringTextFormat() { - QList 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) test.toString(Qt::TextDate); @@ -353,9 +330,7 @@ void tst_QDateTime::toStringTextFormat() void tst_QDateTime::toStringIsoFormat() { - QList 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) test.toString(Qt::ISODate); @@ -364,10 +339,8 @@ void tst_QDateTime::toStringIsoFormat() void tst_QDateTime::addDays() { - QList list; + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QDateTime next; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); QBENCHMARK { foreach (const QDateTime &test, list) next = test.addDays(1); @@ -377,10 +350,7 @@ void tst_QDateTime::addDays() void tst_QDateTime::addDaysTz() { - QTimeZone cet = QTimeZone("Europe/Oslo"); - QList 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) QDateTime result = test.addDays(1); @@ -389,10 +359,8 @@ void tst_QDateTime::addDaysTz() void tst_QDateTime::addMSecs() { - QList list; + const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QDateTime next; - for (int jd = JULIAN_DAY_2010; jd < JULIAN_DAY_2020; ++jd) - list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0))); QBENCHMARK { foreach (const QDateTime &test, list) next = test.addMSecs(1); @@ -402,10 +370,7 @@ void tst_QDateTime::addMSecs() void tst_QDateTime::addMSecsTz() { - QTimeZone cet = QTimeZone("Europe/Oslo"); - QList 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) QDateTime result = test.addMSecs(1); @@ -414,9 +379,7 @@ void tst_QDateTime::addMSecsTz() void tst_QDateTime::toTimeSpec() { - QList 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) test.toTimeSpec(Qt::UTC); @@ -425,9 +388,7 @@ void tst_QDateTime::toTimeSpec() void tst_QDateTime::toOffsetFromUtc() { - QList 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) test.toOffsetFromUtc(3600); @@ -438,9 +399,7 @@ void tst_QDateTime::daysTo() { const QDateTime other = QDateTime::fromMSecsSinceEpoch( qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY); - QList 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) test.daysTo(other); @@ -451,9 +410,7 @@ void tst_QDateTime::msecsTo() { const QDateTime other = QDateTime::fromMSecsSinceEpoch( qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY); - QList 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) test.msecsTo(other); @@ -465,9 +422,7 @@ void tst_QDateTime::equivalent() bool result; const QDateTime other = QDateTime::fromMSecsSinceEpoch( qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY); - QList 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) result = (test == other); @@ -480,9 +435,7 @@ void tst_QDateTime::equivalentUtc() bool result = false; const QDateTime other = QDateTime::fromMSecsSinceEpoch( qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, Qt::UTC); - QList 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) result = (test == other); @@ -495,9 +448,7 @@ void tst_QDateTime::lessThan() bool result = false; const QDateTime other = QDateTime::fromMSecsSinceEpoch( qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY); - QList 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) result = (test < other); @@ -510,9 +461,7 @@ void tst_QDateTime::lessThanUtc() bool result = false; const QDateTime other = QDateTime::fromMSecsSinceEpoch( qint64(JULIAN_DAY_2010 - JULIAN_DAY_1970) * MSECS_PER_DAY, Qt::UTC); - QList 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) result = (test < other); -- cgit v1.2.3 From 14aa4816149bc05de753e3cc00740fc3666aab1b Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 29 Aug 2019 14:16:32 +0200 Subject: Convert foreach to ranged for in QDateTime benchmark Change-Id: I05cf7b1916afa94a9f0f9b83af9b4ebe20a04cf0 Reviewed-by: Marc Mutz --- tests/benchmarks/corelib/time/qdatetime/main.cpp | 68 ++++++++++++------------ 1 file changed, 34 insertions(+), 34 deletions(-) (limited to 'tests/benchmarks') diff --git a/tests/benchmarks/corelib/time/qdatetime/main.cpp b/tests/benchmarks/corelib/time/qdatetime/main.cpp index 2730e7e18b..740e08cc46 100644 --- a/tests/benchmarks/corelib/time/qdatetime/main.cpp +++ b/tests/benchmarks/corelib/time/qdatetime/main.cpp @@ -135,7 +135,7 @@ void tst_QDateTime::isNull() { const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.isNull(); } } @@ -144,7 +144,7 @@ void tst_QDateTime::isValid() { const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.isValid(); } } @@ -153,7 +153,7 @@ void tst_QDateTime::date() { const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.date(); } } @@ -162,7 +162,7 @@ void tst_QDateTime::time() { const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.time(); } } @@ -171,7 +171,7 @@ void tst_QDateTime::timeSpec() { const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.timeSpec(); } } @@ -180,7 +180,7 @@ void tst_QDateTime::offsetFromUtc() { const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.offsetFromUtc(); } } @@ -189,7 +189,7 @@ void tst_QDateTime::timeZoneAbbreviation() { const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.timeZoneAbbreviation(); } } @@ -198,7 +198,7 @@ void tst_QDateTime::toMSecsSinceEpoch() { const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.toMSecsSinceEpoch(); } } @@ -207,7 +207,7 @@ void tst_QDateTime::toMSecsSinceEpoch1950() { const auto list = daily(JULIAN_DAY_1950, JULIAN_DAY_1960); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.toMSecsSinceEpoch(); } } @@ -216,7 +216,7 @@ void tst_QDateTime::toMSecsSinceEpoch2050() { const auto list = daily(JULIAN_DAY_2050, JULIAN_DAY_2060); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.toMSecsSinceEpoch(); } } @@ -226,7 +226,7 @@ void tst_QDateTime::toMSecsSinceEpochTz() qint64 result; const auto list = norse(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) result = test.toMSecsSinceEpoch(); } Q_UNUSED(result); @@ -237,7 +237,7 @@ void tst_QDateTime::toMSecsSinceEpoch1950Tz() qint64 result; const auto list = norse(JULIAN_DAY_1950, JULIAN_DAY_1960); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) result = test.toMSecsSinceEpoch(); } Q_UNUSED(result); @@ -248,7 +248,7 @@ void tst_QDateTime::toMSecsSinceEpoch2050Tz() qint64 result; const auto list = norse(JULIAN_DAY_2050, JULIAN_DAY_2060); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) result = test.toMSecsSinceEpoch(); } Q_UNUSED(result); @@ -258,7 +258,7 @@ void tst_QDateTime::setDate() { 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)); } } @@ -267,7 +267,7 @@ void tst_QDateTime::setTime() { 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)); } } @@ -276,7 +276,7 @@ void tst_QDateTime::setTimeSpec() { const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (QDateTime test, list) + for (QDateTime test : list) test.setTimeSpec(Qt::UTC); } } @@ -285,7 +285,7 @@ void tst_QDateTime::setOffsetFromUtc() { const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (QDateTime test, list) + for (QDateTime test : list) test.setOffsetFromUtc(3600); } } @@ -295,7 +295,7 @@ 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 { - foreach (QDateTime test, list) + for (QDateTime test : list) test.setMSecsSinceEpoch(msecs); } } @@ -305,7 +305,7 @@ 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 { - foreach (QDateTime test, list) + for (QDateTime test : list) test.setMSecsSinceEpoch(msecs); } } @@ -314,7 +314,7 @@ void tst_QDateTime::toString() { 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")); } } @@ -323,7 +323,7 @@ void tst_QDateTime::toStringTextFormat() { 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); } } @@ -332,7 +332,7 @@ void tst_QDateTime::toStringIsoFormat() { 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); } } @@ -342,7 +342,7 @@ void tst_QDateTime::addDays() const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QDateTime next; QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) next = test.addDays(1); } Q_UNUSED(next); @@ -352,7 +352,7 @@ void tst_QDateTime::addDaysTz() { 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); } } @@ -362,7 +362,7 @@ void tst_QDateTime::addMSecs() const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QDateTime next; QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) next = test.addMSecs(1); } Q_UNUSED(next); @@ -372,7 +372,7 @@ void tst_QDateTime::addMSecsTz() { 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); } } @@ -381,7 +381,7 @@ void tst_QDateTime::toTimeSpec() { 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); } } @@ -390,7 +390,7 @@ void tst_QDateTime::toOffsetFromUtc() { const auto list = daily(JULIAN_DAY_2010, JULIAN_DAY_2020); QBENCHMARK { - foreach (const QDateTime &test, list) + for (const QDateTime &test : list) test.toOffsetFromUtc(3600); } } @@ -401,7 +401,7 @@ void tst_QDateTime::daysTo() 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); } } @@ -412,7 +412,7 @@ void tst_QDateTime::msecsTo() 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); } } @@ -424,7 +424,7 @@ void tst_QDateTime::equivalent() 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) @@ -437,7 +437,7 @@ void tst_QDateTime::equivalentUtc() 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) @@ -450,7 +450,7 @@ void tst_QDateTime::lessThan() 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,7 +463,7 @@ void tst_QDateTime::lessThanUtc() 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) -- cgit v1.2.3 From acd7259a03d0168682fedd278ee14ae70a4d87a6 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Thu, 29 Aug 2019 15:27:28 +0200 Subject: Extend QDate's benchmark Test more methods. Document what the existing test covers. Use the right #include for QDate. Change-Id: I051542c244e5bc381aafa3ae38144e246919db7a Reviewed-by: Marc Mutz --- .../corelib/time/qdate/tst_bench_qdate.cpp | 170 ++++++++++++++++++++- 1 file changed, 165 insertions(+), 5 deletions(-) (limited to 'tests/benchmarks') 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 +#include #include +#include class tst_QDate : public QObject { Q_OBJECT + enum : qint64 + { + JULIAN_DAY_2010 = 2455198, + JULIAN_DAY_2011 = 2455563, + JULIAN_DAY_2020 = 2458850, + }; + + static QVector daily(qint64 start, qint64 end); + static QVector 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 tst_QDate::daily(qint64 start, qint64 end) +{ + QVector list; + list.reserve(end - start); + for (qint64 jd = start; jd < end; ++jd) + list.append(QDate::fromJulianDay(jd)); + return list; +} + +QVector tst_QDate::yearly(qint32 first, qint32 last) +{ + QVector 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) -- cgit v1.2.3