summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks
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
parent7e8705f6632428a8d9a937ab5fe087999347b3dd (diff)
parentbf8fcab8bb92ff534c5cec048d6dbebb3b73a348 (diff)
Merge remote-tracking branch 'origin/dev' into wip/qt6
Diffstat (limited to 'tests/benchmarks')
-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
-rw-r--r--tests/benchmarks/gui/image/qimageconversion/tst_qimageconversion.cpp22
-rw-r--r--tests/benchmarks/gui/image/qimagereader/qimagereader.pro2
-rw-r--r--tests/benchmarks/gui/image/qimagereader/tst_qimagereader.cpp17
-rw-r--r--tests/benchmarks/widgets/graphicsview/qgraphicsview/benchapps/chipTest/view.cpp5
-rw-r--r--tests/benchmarks/widgets/graphicsview/qgraphicsview/benchapps/moveItems/main.cpp12
-rw-r--r--tests/benchmarks/widgets/graphicsview/qgraphicsview/benchapps/scrolltest/main.cpp5
9 files changed, 381 insertions, 190 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);
}
}
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()
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<QString, QByteArray> > 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();
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 <QtGui>
-#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 <QtOpenGL>
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 <QtGui>
-#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 <QtGui>
-#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
{