summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmarks')
-rw-r--r--tests/benchmarks/benchmarks.pro1
-rw-r--r--tests/benchmarks/qmatrix4x4/qmatrix4x4.pro6
-rw-r--r--tests/benchmarks/qmatrix4x4/tst_qmatrix4x4.cpp261
-rw-r--r--tests/benchmarks/qstringbuilder/main.cpp174
-rw-r--r--tests/benchmarks/qstringbuilder/qstringbuilder.pro4
5 files changed, 390 insertions, 56 deletions
diff --git a/tests/benchmarks/benchmarks.pro b/tests/benchmarks/benchmarks.pro
index 4c39373..bc41125 100644
--- a/tests/benchmarks/benchmarks.pro
+++ b/tests/benchmarks/benchmarks.pro
@@ -9,6 +9,7 @@ SUBDIRS = containers-associative \
qpixmap \
blendbench \
qstringlist \
+ qmatrix4x4 \
qobject \
qrect \
qregexp \
diff --git a/tests/benchmarks/qmatrix4x4/qmatrix4x4.pro b/tests/benchmarks/qmatrix4x4/qmatrix4x4.pro
new file mode 100644
index 0000000..e82d9de
--- /dev/null
+++ b/tests/benchmarks/qmatrix4x4/qmatrix4x4.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_qmatrix4x4
+
+SOURCES += tst_qmatrix4x4.cpp
+
diff --git a/tests/benchmarks/qmatrix4x4/tst_qmatrix4x4.cpp b/tests/benchmarks/qmatrix4x4/tst_qmatrix4x4.cpp
new file mode 100644
index 0000000..5046b17
--- /dev/null
+++ b/tests/benchmarks/qmatrix4x4/tst_qmatrix4x4.cpp
@@ -0,0 +1,261 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (qt-info@nokia.com)
+**
+** This file is part of the QtOpenGL module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the either Technology Preview License Agreement or the
+** Beta Release License Agreement.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain
+** additional rights. These rights are described in the Nokia Qt LGPL
+** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
+** package.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3.0 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU General Public License version 3.0 requirements will be
+** met: http://www.gnu.org/copyleft/gpl.html.
+**
+** If you are unsure which license is appropriate for your use, please
+** contact the sales department at qt-sales@nokia.com.
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QtTest>
+#include <QtGui/qmatrix4x4.h>
+
+class tst_QMatrix4x4 : public QObject
+{
+ Q_OBJECT
+public:
+ tst_QMatrix4x4() {}
+ ~tst_QMatrix4x4() {}
+
+private slots:
+ void multiply_data();
+ void multiply();
+
+ void multiplyInPlace_data();
+ void multiplyInPlace();
+
+ void multiplyDirect_data();
+ void multiplyDirect();
+
+ void mapVector3D_data();
+ void mapVector3D();
+
+ void mapVector2D_data();
+ void mapVector2D();
+
+ void mapVectorDirect_data();
+ void mapVectorDirect();
+};
+
+static qreal const generalValues[16] =
+ {1.0f, 2.0f, 3.0f, 4.0f,
+ 5.0f, 6.0f, 7.0f, 8.0f,
+ 9.0f, 10.0f, 11.0f, 12.0f,
+ 13.0f, 14.0f, 15.0f, 16.0f};
+
+void tst_QMatrix4x4::multiply_data()
+{
+ QTest::addColumn<QMatrix4x4>("m1");
+ QTest::addColumn<QMatrix4x4>("m2");
+
+ QTest::newRow("identity * identity")
+ << QMatrix4x4() << QMatrix4x4();
+ QTest::newRow("identity * general")
+ << QMatrix4x4() << QMatrix4x4(generalValues);
+ QTest::newRow("general * identity")
+ << QMatrix4x4(generalValues) << QMatrix4x4();
+ QTest::newRow("general * general")
+ << QMatrix4x4(generalValues) << QMatrix4x4(generalValues);
+}
+
+QMatrix4x4 mresult;
+
+void tst_QMatrix4x4::multiply()
+{
+ QFETCH(QMatrix4x4, m1);
+ QFETCH(QMatrix4x4, m2);
+
+ QMatrix4x4 m3;
+
+ QBENCHMARK {
+ m3 = m1 * m2;
+ }
+
+ // Force the result to be stored so the compiler doesn't
+ // optimize away the contents of the benchmark loop.
+ mresult = m3;
+}
+
+void tst_QMatrix4x4::multiplyInPlace_data()
+{
+ multiply_data();
+}
+
+void tst_QMatrix4x4::multiplyInPlace()
+{
+ QFETCH(QMatrix4x4, m1);
+ QFETCH(QMatrix4x4, m2);
+
+ QMatrix4x4 m3;
+
+ QBENCHMARK {
+ m3 = m1;
+ m3 *= m2;
+ }
+
+ // Force the result to be stored so the compiler doesn't
+ // optimize away the contents of the benchmark loop.
+ mresult = m3;
+}
+
+// Use a direct naive multiplication algorithm. This is used
+// to compare against the optimized routines to see if they are
+// actually faster than the naive implementation.
+void tst_QMatrix4x4::multiplyDirect_data()
+{
+ multiply_data();
+}
+void tst_QMatrix4x4::multiplyDirect()
+{
+ QFETCH(QMatrix4x4, m1);
+ QFETCH(QMatrix4x4, m2);
+
+ QMatrix4x4 m3;
+
+ const float *m1data = m1.constData();
+ const float *m2data = m2.constData();
+ float *m3data = m3.data();
+
+ QBENCHMARK {
+ for (int row = 0; row < 4; ++row) {
+ for (int col = 0; col < 4; ++col) {
+ m3data[col * 4 + row] = 0.0f;
+ for (int j = 0; j < 4; ++j) {
+ m3data[col * 4 + row] +=
+ m1data[j * 4 + row] * m2data[col * 4 + j];
+ }
+ }
+ }
+ }
+}
+
+QVector3D vresult;
+
+void tst_QMatrix4x4::mapVector3D_data()
+{
+ QTest::addColumn<QMatrix4x4>("m1");
+
+ QTest::newRow("identity") << QMatrix4x4();
+ QTest::newRow("general") << QMatrix4x4(generalValues);
+
+ QMatrix4x4 t1;
+ t1.translate(-100.5f, 64.0f, 75.25f);
+ QTest::newRow("translate3D") << t1;
+
+ QMatrix4x4 t2;
+ t2.translate(-100.5f, 64.0f);
+ QTest::newRow("translate2D") << t2;
+
+ QMatrix4x4 s1;
+ s1.scale(-100.5f, 64.0f, 75.25f);
+ QTest::newRow("scale3D") << s1;
+
+ QMatrix4x4 s2;
+ s2.scale(-100.5f, 64.0f);
+ QTest::newRow("scale2D") << s2;
+}
+void tst_QMatrix4x4::mapVector3D()
+{
+ QFETCH(QMatrix4x4, m1);
+
+ QVector3D v(10.5f, -2.0f, 3.0f);
+ QVector3D result;
+
+ m1.inferSpecialType();
+
+ QBENCHMARK {
+ result = m1 * v;
+ }
+
+ // Force the result to be stored so the compiler doesn't
+ // optimize away the contents of the benchmark loop.
+ vresult = result;
+}
+
+QPointF vresult2;
+
+void tst_QMatrix4x4::mapVector2D_data()
+{
+ mapVector3D_data();
+}
+void tst_QMatrix4x4::mapVector2D()
+{
+ QFETCH(QMatrix4x4, m1);
+
+ QPointF v(10.5f, -2.0f);
+ QPointF result;
+
+ m1.inferSpecialType();
+
+ QBENCHMARK {
+ result = m1 * v;
+ }
+
+ // Force the result to be stored so the compiler doesn't
+ // optimize away the contents of the benchmark loop.
+ vresult2 = result;
+}
+
+// Use a direct naive multiplication algorithm. This is used
+// to compare against the optimized routines to see if they are
+// actually faster than the naive implementation.
+void tst_QMatrix4x4::mapVectorDirect_data()
+{
+ mapVector3D_data();
+}
+void tst_QMatrix4x4::mapVectorDirect()
+{
+ QFETCH(QMatrix4x4, m1);
+
+ const float *m1data = m1.constData();
+ float v[4] = {10.5f, -2.0f, 3.0f, 1.0f};
+ float result[4];
+
+ QBENCHMARK {
+ for (int row = 0; row < 4; ++row) {
+ result[row] = 0.0f;
+ for (int col = 0; col < 4; ++col) {
+ result[row] += m1data[col * 4 + row] * v[col];
+ }
+ }
+ result[0] /= result[3];
+ result[1] /= result[3];
+ result[2] /= result[3];
+ }
+}
+
+QTEST_MAIN(tst_QMatrix4x4)
+
+#include "tst_qmatrix4x4.moc"
diff --git a/tests/benchmarks/qstringbuilder/main.cpp b/tests/benchmarks/qstringbuilder/main.cpp
index 8eb4e78..d4e2fa0 100644
--- a/tests/benchmarks/qstringbuilder/main.cpp
+++ b/tests/benchmarks/qstringbuilder/main.cpp
@@ -1,17 +1,64 @@
-#include "qstringbuilder.h"
+// Select one of the scenarios below
+#define SCENARIO 3
+
+#if SCENARIO == 1
+// this is the "no harm done" version. Only operator% is active,
+// with NO_CAST * defined
+#define P %
+#undef QT_USE_FAST_OPERATOR_PLUS
+#undef QT_USE_FAST_CONCATENATION
+#define QT_NO_CAST_FROM_ASCII
+#define QT_NO_CAST_TO_ASCII
+#endif
-#include <QDebug>
-#include <QString>
-#include <qtest.h>
+#if SCENARIO == 2
+// this is the "full" version. Operator+ is replaced by a QStringBuilder
+// based version
+// with NO_CAST * defined
+#define P %
+#define QT_USE_FAST_OPERATOR_PLUS
+#define QT_USE_FAST_CONCATENATION
+#define QT_NO_CAST_FROM_ASCII
+#define QT_NO_CAST_TO_ASCII
+#endif
+
+#if SCENARIO == 3
+// this is the "no harm done" version. Only operator% is active,
+// with NO_CAST * _not_ defined
+#define P %
+#undef QT_USE_FAST_OPERATOR_PLUS
+#undef QT_USE_FAST_CONCATENATION
+#undef QT_NO_CAST_FROM_ASCII
+#undef QT_NO_CAST_TO_ASCII
+#endif
+
+#if SCENARIO == 4
+// this is the "full" version. Operator+ is replaced by a QStringBuilder
+// based version
+// with NO_CAST * _not_ defined
+#define P %
+#define QT_USE_FAST_OPERATOR_PLUS
+#define QT_USE_FAST_CONCATENATION
+#undef QT_NO_CAST_FROM_ASCII
+#undef QT_NO_CAST_TO_ASCII
+#endif
+
+#include <qbytearray.h>
+#include <qdebug.h>
+#include <qstring.h>
+#include <qstringbuilder.h>
+
+#include <qtest.h>
#define COMPARE(a, b) QCOMPARE(a, b)
//#define COMPARE(a, b)
#define SEP(s) qDebug() << "\n\n-------- " s " ---------";
-#define L(s) QLatin1String(s)
+
+#define LITERAL "some string literal"
class tst_qstringbuilder : public QObject
{
@@ -19,12 +66,16 @@ class tst_qstringbuilder : public QObject
public:
tst_qstringbuilder()
- : l1literal("some string literal"),
- l1string("some string literal"),
- ba("some string literal"),
+ : l1literal(LITERAL),
+ l1string(LITERAL),
+ ba(LITERAL),
string(l1string),
stringref(&string, 2, 10),
- achar('c')
+ achar('c'),
+ r2(QLatin1String(LITERAL LITERAL)),
+ r3(QLatin1String(LITERAL LITERAL LITERAL)),
+ r4(QLatin1String(LITERAL LITERAL LITERAL LITERAL)),
+ r5(QLatin1String(LITERAL LITERAL LITERAL LITERAL LITERAL))
{}
@@ -51,10 +102,10 @@ public:
int s = 0;
for (int i = 0; i < N; ++i) {
#if 0
- s += QString(l1literal % l1literal).size();
- s += QString(l1literal % l1literal % l1literal).size();
- s += QString(l1literal % l1literal % l1literal % l1literal).size();
- s += QString(l1literal % l1literal % l1literal % l1literal % l1literal).size();
+ s += QString(l1literal P l1literal).size();
+ s += QString(l1literal P l1literal P l1literal).size();
+ s += QString(l1literal P l1literal P l1literal P l1literal).size();
+ s += QString(l1literal P l1literal P l1literal P l1literal P l1literal).size();
#endif
s += QString(achar % l1literal % achar).size();
}
@@ -71,24 +122,30 @@ private slots:
void separator_1() { SEP("literal + literal (builder first)"); }
void b_2_l1literal() {
- QBENCHMARK { r = l1literal % l1literal; }
- COMPARE(r, QString(l1string + l1string));
+ QBENCHMARK { r = l1literal P l1literal; }
+ COMPARE(r, r2);
+ }
+ #ifndef QT_NO_CAST_FROM_ASCII
+ void b_l1literal_LITERAL() {
+ QBENCHMARK { r = l1literal P LITERAL; }
+ COMPARE(r, r2);
}
+ #endif
void s_2_l1string() {
QBENCHMARK { r = l1string + l1string; }
- COMPARE(r, QString(l1literal % l1literal));
+ COMPARE(r, r2);
}
void separator_2() { SEP("2 strings"); }
void b_2_string() {
- QBENCHMARK { r = string % string; }
- COMPARE(r, QString(string + string));
+ QBENCHMARK { r = string P string; }
+ COMPARE(r, r2);
}
void s_2_string() {
QBENCHMARK { r = string + string; }
- COMPARE(r, QString(string % string));
+ COMPARE(r, r2);
}
@@ -107,12 +164,12 @@ private slots:
void separator_2b() { SEP("3 strings"); }
void b_3_string() {
- QBENCHMARK { r = string % string % string; }
- COMPARE(r, QString(string + string + string));
+ QBENCHMARK { r = string P string P string; }
+ COMPARE(r, r3);
}
void s_3_string() {
QBENCHMARK { r = string + string + string; }
- COMPARE(r, QString(string % string % string));
+ COMPARE(r, r3);
}
@@ -120,56 +177,66 @@ private slots:
void b_string_l1literal() {
QBENCHMARK { r = string % l1literal; }
- COMPARE(r, QString(string + l1string));
+ COMPARE(r, r2);
}
+ #ifndef QT_NO_CAST_FROM_ASCII
+ void b_string_LITERAL() {
+ QBENCHMARK { r = string P LITERAL; }
+ COMPARE(r, r2);
+ }
+ void b_LITERAL_string() {
+ QBENCHMARK { r = LITERAL P string; }
+ COMPARE(r, r2);
+ }
+ #endif
void b_string_l1string() {
- QBENCHMARK { r = string % l1string; }
- COMPARE(r, QString(string + l1string));
+ QBENCHMARK { r = string P l1string; }
+ COMPARE(r, r2);
}
void s_string_l1literal() {
QBENCHMARK { r = string + l1string; }
- COMPARE(r, QString(string % l1literal));
+ COMPARE(r, r2);
}
void s_string_l1string() {
QBENCHMARK { r = string + l1string; }
- COMPARE(r, QString(string % l1literal));
+ COMPARE(r, r2);
}
void separator_3() { SEP("3 literals"); }
void b_3_l1literal() {
- QBENCHMARK { r = l1literal % l1literal % l1literal; }
- COMPARE(r, QString(l1string + l1string + l1string));
+ QBENCHMARK { r = l1literal P l1literal P l1literal; }
+ COMPARE(r, r3);
}
void s_3_l1string() {
QBENCHMARK { r = l1string + l1string + l1string; }
- COMPARE(r, QString(l1literal % l1literal % l1literal));
+ COMPARE(r, r3);
}
void separator_4() { SEP("4 literals"); }
void b_4_l1literal() {
- QBENCHMARK { r = l1literal % l1literal % l1literal % l1literal; }
- COMPARE(r, QString(l1string + l1string + l1string + l1string));
+ QBENCHMARK { r = l1literal P l1literal P l1literal P l1literal; }
+ COMPARE(r, r4);
}
void s_4_l1string() {
QBENCHMARK { r = l1string + l1string + l1string + l1string; }
- COMPARE(r, QString(l1literal % l1literal % l1literal % l1literal));
+ COMPARE(r, r4);
}
void separator_5() { SEP("5 literals"); }
void b_5_l1literal() {
- QBENCHMARK { r = l1literal % l1literal % l1literal % l1literal %l1literal; }
- COMPARE(r, QString(l1string + l1string + l1string + l1string + l1string));
+ QBENCHMARK { r = l1literal P l1literal P l1literal P l1literal P l1literal; }
+ COMPARE(r, r5);
}
void s_5_l1string() {
QBENCHMARK { r = l1string + l1string + l1string + l1string + l1string; }
- COMPARE(r, QString(l1literal % l1literal % l1literal % l1literal % l1literal));
+ COMPARE(r, r5);
}
@@ -177,12 +244,12 @@ private slots:
void b_string_4_char() {
QBENCHMARK { r = string + achar + achar + achar + achar; }
- COMPARE(r, QString(string % achar % achar % achar % achar));
+ COMPARE(r, QString(string P achar P achar P achar P achar));
}
void s_string_4_char() {
QBENCHMARK { r = string + achar + achar + achar + achar; }
- COMPARE(r, QString(string % achar % achar % achar % achar));
+ COMPARE(r, QString(string P achar P achar P achar P achar));
}
@@ -190,26 +257,26 @@ private slots:
void b_char_string_char() {
QBENCHMARK { r = achar + string + achar; }
- COMPARE(r, QString(achar % string % achar));
+ COMPARE(r, QString(achar P string P achar));
}
void s_char_string_char() {
QBENCHMARK { r = achar + string + achar; }
- COMPARE(r, QString(achar % string % achar));
+ COMPARE(r, QString(achar P string P achar));
}
void separator_8() { SEP("string.arg"); }
void b_string_arg() {
- const QString pattern = l1string + QLatin1String("%1") + l1string;
- QBENCHMARK { r = l1literal % string % l1literal; }
- COMPARE(r, QString(l1string + string + l1string));
+ const QString pattern = l1string + QString::fromLatin1("%1") + l1string;
+ QBENCHMARK { r = l1literal P string P l1literal; }
+ COMPARE(r, r3);
}
void s_string_arg() {
const QString pattern = l1string + QLatin1String("%1") + l1string;
QBENCHMARK { r = pattern.arg(string); }
- COMPARE(r, QString(l1string + string + l1string));
+ COMPARE(r, r3);
}
void s_bytearray_arg() {
@@ -223,16 +290,16 @@ private slots:
void b_reserve() {
QBENCHMARK {
r.clear();
- r = string % string % string % string;
+ r = string P string P string P string;
}
- COMPARE(r, QString(string + string + string + string));
+ COMPARE(r, r4);
}
void b_reserve_lit() {
QBENCHMARK {
r.clear();
- r = string % l1literal % string % string;
+ r = string P l1literal P string P string;
}
- COMPARE(r, QString(string + string + string + string));
+ COMPARE(r, r4);
}
void s_reserve() {
QBENCHMARK {
@@ -243,7 +310,7 @@ private slots:
r += string;
r += string;
}
- COMPARE(r, QString(string + string + string + string));
+ COMPARE(r, r4);
}
void s_reserve_lit() {
QBENCHMARK {
@@ -256,7 +323,7 @@ private slots:
r += string;
r += string;
}
- COMPARE(r, QString(string + string + string + string));
+ COMPARE(r, r4);
}
private:
@@ -266,6 +333,7 @@ private:
const QString string;
const QStringRef stringref;
const QLatin1Char achar;
+ const QString r2, r3, r4, r5;
QString r;
};
@@ -280,12 +348,14 @@ int main(int argc, char *argv[])
//QString("x") % 2; // Sanity test, should only compile when the
// operator%(QString, int) is visible.
- if (argc == 2 && (argv[1] == L("--run-builder") || argv[1] == L("-b"))) {
+ if (argc == 2 && (QLatin1String(argv[1]) == QLatin1String("--run-builder")
+ || QLatin1String(argv[1]) == QLatin1String("-b"))) {
tst_qstringbuilder test;
return test.run_builder();
}
- if (argc == 2 && (argv[1] == L("--run-traditional") || argv[1] == L("-t"))) {
+ if (argc == 2 && (QLatin1String(argv[1]) == QLatin1String("--run-traditional")
+ || QLatin1String(argv[1]) == QLatin1String("-t"))) {
tst_qstringbuilder test;
return test.run_traditional();
}
diff --git a/tests/benchmarks/qstringbuilder/qstringbuilder.pro b/tests/benchmarks/qstringbuilder/qstringbuilder.pro
index 02daaaa..79171b4 100644
--- a/tests/benchmarks/qstringbuilder/qstringbuilder.pro
+++ b/tests/benchmarks/qstringbuilder/qstringbuilder.pro
@@ -2,10 +2,6 @@ load(qttest_p4)
TEMPLATE = app
TARGET = tst_qstringbuilder
-# Uncomment to test compilation of the drop-in
-# replacement operator+()
-#DEFINES += QT_USE_FAST_OPERATOR_PLUS
-
QMAKE_CXXFLAGS += -g
QMAKE_CFLAGS += -g