summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/corelib/tools
diff options
context:
space:
mode:
authorBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2010-02-08 13:01:08 (GMT)
committerBjørn Erik Nilsen <bjorn.nilsen@nokia.com>2010-02-08 15:03:39 (GMT)
commit020830966e08239854ac207ec28663a80c6e0647 (patch)
tree38cec073cf32745aefac3803d1e0859f32d3c74d /tests/benchmarks/corelib/tools
parent43a9c48554579d76e1f1267fbd70f488f22fd408 (diff)
downloadQt-020830966e08239854ac207ec28663a80c6e0647.zip
Qt-020830966e08239854ac207ec28663a80c6e0647.tar.gz
Qt-020830966e08239854ac207ec28663a80c6e0647.tar.bz2
Restructure tests/benchmarks directory.
We follow the same structure as used in the src directory. This makes it easier to navigate through the jungel, especially now that we are going to add functional tests etc.
Diffstat (limited to 'tests/benchmarks/corelib/tools')
-rw-r--r--tests/benchmarks/corelib/tools/containers-associative/containers-associative.pro8
-rw-r--r--tests/benchmarks/corelib/tools/containers-associative/main.cpp143
-rw-r--r--tests/benchmarks/corelib/tools/containers-sequential/containers-sequential.pro8
-rw-r--r--tests/benchmarks/corelib/tools/containers-sequential/main.cpp265
-rw-r--r--tests/benchmarks/corelib/tools/qbytearray/main.cpp92
-rwxr-xr-xtests/benchmarks/corelib/tools/qbytearray/qbytearray.pro12
-rw-r--r--tests/benchmarks/corelib/tools/qrect/main.cpp329
-rw-r--r--tests/benchmarks/corelib/tools/qrect/qrect.pro12
-rw-r--r--tests/benchmarks/corelib/tools/qregexp/main.cpp290
-rw-r--r--tests/benchmarks/corelib/tools/qregexp/qregexp.pro12
-rw-r--r--tests/benchmarks/corelib/tools/qstring/main.cpp147
-rw-r--r--tests/benchmarks/corelib/tools/qstring/qstring.pro16
-rw-r--r--tests/benchmarks/corelib/tools/qstring/utf-8.txt72
-rw-r--r--tests/benchmarks/corelib/tools/qstringbuilder/main.cpp464
-rw-r--r--tests/benchmarks/corelib/tools/qstringbuilder/qstringbuilder.pro12
-rw-r--r--tests/benchmarks/corelib/tools/qstringlist/.gitignore1
-rw-r--r--tests/benchmarks/corelib/tools/qstringlist/main.cpp193
-rw-r--r--tests/benchmarks/corelib/tools/qstringlist/qstringlist.pro6
-rw-r--r--tests/benchmarks/corelib/tools/tools.pro10
19 files changed, 2092 insertions, 0 deletions
diff --git a/tests/benchmarks/corelib/tools/containers-associative/containers-associative.pro b/tests/benchmarks/corelib/tools/containers-associative/containers-associative.pro
new file mode 100644
index 0000000..c6f3fa6
--- /dev/null
+++ b/tests/benchmarks/corelib/tools/containers-associative/containers-associative.pro
@@ -0,0 +1,8 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_containers-associative
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+SOURCES += main.cpp
diff --git a/tests/benchmarks/corelib/tools/containers-associative/main.cpp b/tests/benchmarks/corelib/tools/containers-associative/main.cpp
new file mode 100644
index 0000000..4c6dae4
--- /dev/null
+++ b/tests/benchmarks/corelib/tools/containers-associative/main.cpp
@@ -0,0 +1,143 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite 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 Technology Preview License Agreement accompanying
+** this package.
+**
+** 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.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QtGui>
+#include <QString>
+
+#include <qtest.h>
+
+class tst_associative_containers : public QObject
+{
+ Q_OBJECT
+private slots:
+ void insert_data();
+ void insert();
+ void lookup_data();
+ void lookup();
+};
+
+template <typename T>
+void testInsert(int size)
+{
+ T container;
+
+ QBENCHMARK {
+ for (int i = 0; i < size; ++i)
+ container.insert(i, i);
+ }
+}
+
+void tst_associative_containers::insert_data()
+{
+ QTest::addColumn<bool>("useHash");
+ QTest::addColumn<int>("size");
+
+ for (int size = 10; size < 20000; size += 100) {
+
+ const QByteArray sizeString = QByteArray::number(size);
+
+ QTest::newRow(("hash--" + sizeString).constData()) << true << size;
+ QTest::newRow(("map--" + sizeString).constData()) << false << size;
+ }
+}
+
+void tst_associative_containers::insert()
+{
+ QFETCH(bool, useHash);
+ QFETCH(int, size);
+
+ QHash<int, int> testHash;
+ QMap<int, int> testMap;
+
+ if (useHash) {
+ testInsert<QHash<int, int> >(size);
+ } else {
+ testInsert<QMap<int, int> >(size);
+ }
+}
+
+void tst_associative_containers::lookup_data()
+{
+// setReportType(LineChartReport);
+// setChartTitle("Time to call value(), with an increasing number of items in the container");
+
+ QTest::addColumn<bool>("useHash");
+ QTest::addColumn<int>("size");
+
+ for (int size = 10; size < 20000; size += 100) {
+
+ const QByteArray sizeString = QByteArray::number(size);
+
+ QTest::newRow(("hash--" + sizeString).constData()) << true << size;
+ QTest::newRow(("map--" + sizeString).constData()) << false << size;
+ }
+}
+
+template <typename T>
+void testLookup(int size)
+{
+ T container;
+
+ for (int i = 0; i < size; ++i)
+ container.insert(i, i);
+
+ int val;
+
+ QBENCHMARK {
+ for (int i = 0; i < size; ++i)
+ val = container.value(i);
+
+ }
+}
+
+void tst_associative_containers::lookup()
+{
+ QFETCH(bool, useHash);
+ QFETCH(int, size);
+
+ if (useHash) {
+ testLookup<QHash<int, int> >(size);
+ } else {
+ testLookup<QMap<int, int> >(size);
+ }
+}
+
+QTEST_MAIN(tst_associative_containers)
+#include "main.moc"
diff --git a/tests/benchmarks/corelib/tools/containers-sequential/containers-sequential.pro b/tests/benchmarks/corelib/tools/containers-sequential/containers-sequential.pro
new file mode 100644
index 0000000..bf6db44
--- /dev/null
+++ b/tests/benchmarks/corelib/tools/containers-sequential/containers-sequential.pro
@@ -0,0 +1,8 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_containers-sequential
+DEPENDPATH += .
+INCLUDEPATH += .
+
+# Input
+SOURCES += main.cpp
diff --git a/tests/benchmarks/corelib/tools/containers-sequential/main.cpp b/tests/benchmarks/corelib/tools/containers-sequential/main.cpp
new file mode 100644
index 0000000..a6e405c
--- /dev/null
+++ b/tests/benchmarks/corelib/tools/containers-sequential/main.cpp
@@ -0,0 +1,265 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite 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 Technology Preview License Agreement accompanying
+** this package.
+**
+** 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.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+// This file contains benchmarks for comparing QVector against std::vector
+
+#include <QtCore>
+#include <QVector>
+#include <vector>
+
+#include <qtest.h>
+
+template <typename T> // T is the item type
+class UseCases {
+public:
+ virtual ~UseCases() {}
+
+ // Use case: Insert \a size items into the vector.
+ virtual void insert(int size) = 0;
+
+ // Use case: Lookup \a size items from the vector.
+ virtual void lookup(int size) = 0;
+};
+
+template <typename T>
+T * f(T *ts) // dummy function to prevent code from being optimized away by the compiler
+{
+ return ts;
+}
+
+// This subclass implements the use cases using QVector as efficiently as possible.
+template <typename T>
+class UseCases_QVector : public UseCases<T>
+{
+ void insert(int size)
+ {
+ QVector<T> v;
+ T t;
+ QBENCHMARK {
+ for (int i = 0; i < size; ++i)
+ v.append(t);
+ }
+ }
+
+ void lookup(int size)
+ {
+ QVector<T> v;
+
+ T t;
+ for (int i = 0; i < size; ++i)
+ v.append(t);
+
+ T *ts = new T[size];
+ QBENCHMARK {
+ for (int i = 0; i < size; ++i)
+ ts[i] = v.value(i);
+ }
+ f<T>(ts);
+ delete[] ts;
+ }
+};
+
+// This subclass implements the use cases using std::vector as efficiently as possible.
+template <typename T>
+class UseCases_stdvector : public UseCases<T>
+{
+ void insert(int size)
+ {
+ std::vector<T> v;
+ T t;
+ QBENCHMARK {
+ for (int i = 0; i < size; ++i)
+ v.push_back(t);
+ }
+ }
+
+ void lookup(int size)
+ {
+ std::vector<T> v;
+
+ T t;
+ for (int i = 0; i < size; ++i)
+ v.push_back(t);
+
+ T *ts = new T[size];
+ QBENCHMARK {
+ for (int i = 0; i < size; ++i)
+ ts[i] = v[i];
+ }
+ f<T>(ts);
+ delete[] ts;
+ }
+};
+
+struct Large { // A "large" item type
+ int x[1000];
+};
+
+// Symbian devices typically have limited memory
+#ifdef Q_OS_SYMBIAN
+# define LARGE_MAX_SIZE 2000
+#else
+# define LARGE_MAX_SIZE 20000
+#endif
+
+class tst_vector_vs_std : public QObject
+{
+ Q_OBJECT
+public:
+ tst_vector_vs_std()
+ {
+ useCases_QVector_int = new UseCases_QVector<int>;
+ useCases_stdvector_int = new UseCases_stdvector<int>;
+
+ useCases_QVector_Large = new UseCases_QVector<Large>;
+ useCases_stdvector_Large = new UseCases_stdvector<Large>;
+ }
+
+private:
+ UseCases<int> *useCases_QVector_int;
+ UseCases<int> *useCases_stdvector_int;
+ UseCases<Large> *useCases_QVector_Large;
+ UseCases<Large> *useCases_stdvector_Large;
+
+private slots:
+ void insert_int_data();
+ void insert_int();
+ void insert_Large_data();
+ void insert_Large();
+ void lookup_int_data();
+ void lookup_int();
+ void lookup_Large_data();
+ void lookup_Large();
+};
+
+void tst_vector_vs_std::insert_int_data()
+{
+ QTest::addColumn<bool>("useStd");
+ QTest::addColumn<int>("size");
+
+ for (int size = 10; size < 20000; size += 100) {
+ const QByteArray sizeString = QByteArray::number(size);
+ QTest::newRow(("std::vector-int--" + sizeString).constData()) << true << size;
+ QTest::newRow(("QVector-int--" + sizeString).constData()) << false << size;
+ }
+}
+
+void tst_vector_vs_std::insert_int()
+{
+ QFETCH(bool, useStd);
+ QFETCH(int, size);
+
+ if (useStd)
+ useCases_stdvector_int->insert(size);
+ else
+ useCases_QVector_int->insert(size);
+}
+
+void tst_vector_vs_std::insert_Large_data()
+{
+ QTest::addColumn<bool>("useStd");
+ QTest::addColumn<int>("size");
+
+ for (int size = 10; size < LARGE_MAX_SIZE; size += 100) {
+ const QByteArray sizeString = QByteArray::number(size);
+ QTest::newRow(("std::vector-Large--" + sizeString).constData()) << true << size;
+ QTest::newRow(("QVector-Large--" + sizeString).constData()) << false << size;
+ }
+}
+
+void tst_vector_vs_std::insert_Large()
+{
+ QFETCH(bool, useStd);
+ QFETCH(int, size);
+
+ if (useStd)
+ useCases_stdvector_Large->insert(size);
+ else
+ useCases_QVector_Large->insert(size);
+}
+
+void tst_vector_vs_std::lookup_int_data()
+{
+ QTest::addColumn<bool>("useStd");
+ QTest::addColumn<int>("size");
+
+ for (int size = 10; size < 20000; size += 100) {
+ const QByteArray sizeString = QByteArray::number(size);
+ QTest::newRow(("std::vector-int--" + sizeString).constData()) << true << size;
+ QTest::newRow(("QVector-int--" + sizeString).constData()) << false << size;
+ }
+}
+
+void tst_vector_vs_std::lookup_int()
+{
+ QFETCH(bool, useStd);
+ QFETCH(int, size);
+
+ if (useStd)
+ useCases_stdvector_int->lookup(size);
+ else
+ useCases_QVector_int->lookup(size);
+}
+
+void tst_vector_vs_std::lookup_Large_data()
+{
+ QTest::addColumn<bool>("useStd");
+ QTest::addColumn<int>("size");
+
+ for (int size = 10; size < LARGE_MAX_SIZE; size += 100) {
+ const QByteArray sizeString = QByteArray::number(size);
+ QTest::newRow(("std::vector-Large--" + sizeString).constData()) << true << size;
+ QTest::newRow(("QVector-Large--" + sizeString).constData()) << false << size;
+ }
+}
+
+void tst_vector_vs_std::lookup_Large()
+{
+ QFETCH(bool, useStd);
+ QFETCH(int, size);
+
+ if (useStd)
+ useCases_stdvector_Large->lookup(size);
+ else
+ useCases_QVector_Large->lookup(size);
+}
+
+QTEST_MAIN(tst_vector_vs_std)
+#include "main.moc"
diff --git a/tests/benchmarks/corelib/tools/qbytearray/main.cpp b/tests/benchmarks/corelib/tools/qbytearray/main.cpp
new file mode 100644
index 0000000..22d4815
--- /dev/null
+++ b/tests/benchmarks/corelib/tools/qbytearray/main.cpp
@@ -0,0 +1,92 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite 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 Technology Preview License Agreement accompanying
+** this package.
+**
+** 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.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QDebug>
+#include <QIODevice>
+#include <QFile>
+#include <QString>
+
+#include <qtest.h>
+
+
+class tst_qbytearray : public QObject
+{
+ Q_OBJECT
+private slots:
+ void append();
+ void append_data();
+};
+
+
+void tst_qbytearray::append_data()
+{
+ QTest::addColumn<int>("size");
+ QTest::newRow("1") << int(1);
+ QTest::newRow("10") << int(10);
+ QTest::newRow("100") << int(100);
+ QTest::newRow("1000") << int(1000);
+ QTest::newRow("10000") << int(10000);
+ QTest::newRow("100000") << int(100000);
+ QTest::newRow("1000000") << int(1000000);
+ QTest::newRow("10000000") << int(10000000);
+ QTest::newRow("100000000") << int(100000000);
+}
+
+void tst_qbytearray::append()
+{
+ QFETCH(int, size);
+
+#ifdef Q_OS_SYMBIAN
+ if (size > 1000000)
+ QSKIP("Skipped due to limited memory in many Symbian devices.", SkipSingle);
+#endif
+
+ QByteArray ba;
+ QBENCHMARK {
+ QByteArray ba2(size, 'x');
+ ba.append(ba2);
+ ba.clear();
+ }
+}
+
+
+QTEST_MAIN(tst_qbytearray)
+
+#include "main.moc"
diff --git a/tests/benchmarks/corelib/tools/qbytearray/qbytearray.pro b/tests/benchmarks/corelib/tools/qbytearray/qbytearray.pro
new file mode 100755
index 0000000..a0bf021
--- /dev/null
+++ b/tests/benchmarks/corelib/tools/qbytearray/qbytearray.pro
@@ -0,0 +1,12 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_qbytearray
+DEPENDPATH += .
+INCLUDEPATH += .
+
+QT -= gui
+
+CONFIG += release
+
+# Input
+SOURCES += main.cpp
diff --git a/tests/benchmarks/corelib/tools/qrect/main.cpp b/tests/benchmarks/corelib/tools/qrect/main.cpp
new file mode 100644
index 0000000..e293bfa
--- /dev/null
+++ b/tests/benchmarks/corelib/tools/qrect/main.cpp
@@ -0,0 +1,329 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite 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 Technology Preview License Agreement accompanying
+** this package.
+**
+** 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.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+// This file contains benchmarks for QRect/QRectF functions.
+
+#include <QDebug>
+#include <qtest.h>
+
+class tst_qrect : public QObject
+{
+ Q_OBJECT
+private slots:
+ // QRect functions:
+ void contains_point_data();
+ void contains_point();
+ void contains_rect_data();
+ void contains_rect();
+ void intersects_data();
+ void intersects();
+ void intersected_data();
+ void intersected();
+ void united_data();
+ void united();
+
+ // QRectF functions:
+ void contains_point_f_data();
+ void contains_point_f();
+ void contains_rect_f_data();
+ void contains_rect_f();
+ void intersects_f_data();
+ void intersects_f();
+ void intersected_f_data();
+ void intersected_f();
+ void united_f_data();
+ void united_f();
+};
+
+struct RectRectCombination
+{
+ QString tag;
+ qreal x1, y1, w1, h1, x2, y2, w2, h2;
+ RectRectCombination(
+ const QString &tag,
+ const qreal x1, const qreal y1, const qreal w1, const qreal h1,
+ const qreal x2, const qreal y2, const qreal w2, const qreal h2)
+ : tag(tag), x1(x1), y1(y1), w1(w1), h1(h1), x2(x2), y2(y2), w2(w2), h2(h2) {}
+};
+
+static QList<RectRectCombination> createRectRectCombinations()
+{
+ QList<RectRectCombination> result;
+ result << RectRectCombination("null", 0, 0, 0, 0, 0, 0, 0, 0);
+ result << RectRectCombination("null1", 0, 0, 0, 0, 0, 0, 10, 10);
+ result << RectRectCombination("null2", 0, 0, 10, 10, 0, 0, 0, 0);
+
+ result << RectRectCombination("miss", 0, 0, 10, 10, 11, 11, 10, 10);
+ result << RectRectCombination("intersect", 0, 0, 10, 10, 5, 5, 10, 10);
+ result << RectRectCombination("contain1", 0, 0, 10, 10, 1, 1, 8, 8);
+ result << RectRectCombination("contain2", 1, 1, 8, 8, 0, 0, 10, 10);
+
+ result << RectRectCombination("miss_flip1", 9, 9, -10, -10, 11, 11, 10, 10);
+ result << RectRectCombination("intersect_flip1", 9, 9, -10, -10, 5, 5, 10, 10);
+ result << RectRectCombination("contain1_flip1", 9, 9, -10, -10, 1, 1, 8, 8);
+ result << RectRectCombination("contain2_flip1", 8, 8, -8, -8, 0, 0, 10, 10);
+
+ result << RectRectCombination("miss_flip2", 0, 0, 10, 10, 20, 20, -10, -10);
+ result << RectRectCombination("intersect_flip2", 0, 0, 10, 10, 14, 14, -10, -10);
+ result << RectRectCombination("contain1_flip2", 0, 0, 10, 10, 8, 8, -8, -8);
+ result << RectRectCombination("contain2_flip2", 1, 1, 8, 8, 9, 9, -10, -10);
+
+ return result;
+}
+
+static void addRectRectData(bool includeProperArg = false)
+{
+ QTest::addColumn<QRectF>("rf1");
+ QTest::addColumn<QRectF>("rf2");
+ if (includeProperArg)
+ QTest::addColumn<bool>("proper");
+ for (int i = 0; i < (includeProperArg ? 2 : 1); ++i) {
+ QList<RectRectCombination> combinations = createRectRectCombinations();
+ foreach (RectRectCombination c, combinations) {
+ QTestData &testData = QTest::newRow(c.tag.toLatin1().data());
+ QRectF r1(c.x1, c.y1, c.w1, c.h1);
+ QRectF r2(c.x2, c.y2, c.w2, c.h2);
+ testData << r1 << r2;
+ if (includeProperArg)
+ testData << (i == 0);
+ }
+ }
+}
+
+struct RectPointCombination
+{
+ QString tag;
+ qreal x, y, w, h, px, py;
+ RectPointCombination(
+ const QString &tag,
+ const qreal x, const qreal y, const qreal w, const qreal h, const qreal px, const qreal py)
+ : tag(tag), x(x), y(y), w(w), h(h), px(px), py(py) {}
+};
+
+static QList<RectPointCombination> createRectPointCombinations()
+{
+ QList<RectPointCombination> result;
+ result << RectPointCombination("null", 0, 0, 0, 0, 0, 0);
+
+ result << RectPointCombination("miss", 0, 0, 10, 10, -1, -1);
+ result << RectPointCombination("contain", 0, 0, 10, 10, 0, 0);
+ result << RectPointCombination("contain_proper", 0, 0, 10, 10, 1, 1);
+
+ result << RectPointCombination("miss_flip", 9, 9, -10, -10, -1, -1);
+ result << RectPointCombination("contain_flip", 9, 9, -10, -10, 0, 0);
+ result << RectPointCombination("contain_flip_proper", 9, 9, -10, -10, 1, 1);
+
+ return result;
+}
+
+static void addRectPointData(bool includeProperArg = false)
+{
+ QTest::addColumn<QRectF>("rf");
+ QTest::addColumn<QPointF>("pf");
+ if (includeProperArg)
+ QTest::addColumn<bool>("proper");
+ for (int i = 0; i < (includeProperArg ? 2 : 1); ++i) {
+ QList<RectPointCombination> combinations = createRectPointCombinations();
+ foreach (RectPointCombination c, combinations) {
+ QTestData &testData = QTest::newRow(c.tag.toLatin1().data());
+ QRectF r(c.x, c.y, c.w, c.h);
+ QPointF p(c.px, c.py);
+ testData << r << p;
+ if (includeProperArg)
+ testData << (i == 0);
+ }
+ }
+}
+
+void tst_qrect::contains_point_data()
+{
+ addRectPointData(true);
+}
+
+void tst_qrect::contains_point()
+{
+ QFETCH(QRectF, rf);
+ QFETCH(QPointF, pf);
+ QFETCH(bool, proper);
+ QRect r(rf.toRect());
+ QPoint p(pf.toPoint());
+ QBENCHMARK {
+ r.contains(p, proper);
+ }
+}
+
+void tst_qrect::contains_rect_data()
+{
+ addRectRectData(true);
+}
+
+void tst_qrect::contains_rect()
+{
+ QFETCH(QRectF, rf1);
+ QFETCH(QRectF, rf2);
+ QFETCH(bool, proper);
+ QRect r1(rf1.toRect());
+ QRect r2(rf2.toRect());
+ QBENCHMARK {
+ r1.contains(r2, proper);
+ }
+}
+
+void tst_qrect::intersects_data()
+{
+ addRectRectData();
+}
+
+void tst_qrect::intersects()
+{
+ QFETCH(QRectF, rf1);
+ QFETCH(QRectF, rf2);
+ QRect r1(rf1.toRect());
+ QRect r2(rf2.toRect());
+ QBENCHMARK {
+ r1.intersects(r2);
+ }
+}
+
+void tst_qrect::intersected_data()
+{
+ addRectRectData();
+}
+
+void tst_qrect::intersected()
+{
+ QFETCH(QRectF, rf1);
+ QFETCH(QRectF, rf2);
+ QRect r1(rf1.toRect());
+ QRect r2(rf2.toRect());
+ QBENCHMARK {
+ r1.intersected(r2);
+ }
+}
+
+void tst_qrect::united_data()
+{
+ addRectRectData();
+}
+
+void tst_qrect::united()
+{
+ QFETCH(QRectF, rf1);
+ QFETCH(QRectF, rf2);
+ QRect r1(rf1.toRect());
+ QRect r2(rf2.toRect());
+ QBENCHMARK {
+ r1.united(r2);
+ }
+}
+
+void tst_qrect::contains_point_f_data()
+{
+ addRectPointData();
+}
+
+void tst_qrect::contains_point_f()
+{
+ QFETCH(QRectF, rf);
+ QFETCH(QPointF, pf);
+ QBENCHMARK {
+ rf.contains(pf);
+ }
+}
+
+void tst_qrect::contains_rect_f_data()
+{
+ addRectRectData();
+}
+
+void tst_qrect::contains_rect_f()
+{
+ QFETCH(QRectF, rf1);
+ QFETCH(QRectF, rf2);
+ QBENCHMARK {
+ rf1.contains(rf2);
+ }
+}
+
+void tst_qrect::intersects_f_data()
+{
+ addRectRectData();
+}
+
+void tst_qrect::intersects_f()
+{
+ QFETCH(QRectF, rf1);
+ QFETCH(QRectF, rf2);
+ QBENCHMARK {
+ rf1.intersects(rf2);
+ }
+}
+
+void tst_qrect::intersected_f_data()
+{
+ addRectRectData();
+}
+
+void tst_qrect::intersected_f()
+{
+ QFETCH(QRectF, rf1);
+ QFETCH(QRectF, rf2);
+ QBENCHMARK {
+ rf1.intersected(rf2);
+ }
+}
+
+void tst_qrect::united_f_data()
+{
+ addRectRectData();
+}
+
+void tst_qrect::united_f()
+{
+ QFETCH(QRectF, rf1);
+ QFETCH(QRectF, rf2);
+ QBENCHMARK {
+ rf1.united(rf2);
+ }
+}
+
+QTEST_MAIN(tst_qrect)
+
+#include "main.moc"
diff --git a/tests/benchmarks/corelib/tools/qrect/qrect.pro b/tests/benchmarks/corelib/tools/qrect/qrect.pro
new file mode 100644
index 0000000..6e35119
--- /dev/null
+++ b/tests/benchmarks/corelib/tools/qrect/qrect.pro
@@ -0,0 +1,12 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_qrect
+DEPENDPATH += .
+INCLUDEPATH += .
+
+QT -= gui
+
+CONFIG += release
+
+# Input
+SOURCES += main.cpp
diff --git a/tests/benchmarks/corelib/tools/qregexp/main.cpp b/tests/benchmarks/corelib/tools/qregexp/main.cpp
new file mode 100644
index 0000000..ab9ed71
--- /dev/null
+++ b/tests/benchmarks/corelib/tools/qregexp/main.cpp
@@ -0,0 +1,290 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite 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 Technology Preview License Agreement accompanying
+** this package.
+**
+** 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.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QDebug>
+#include <QRegExp>
+#include <QString>
+
+#include <qtest.h>
+
+
+class tst_qregexp : public QObject
+{
+ Q_OBJECT
+private slots:
+ void escape_old();
+ void escape_old_data() { escape_data(); }
+ void escape_new1();
+ void escape_new1_data() { escape_data(); }
+ void escape_new2();
+ void escape_new2_data() { escape_data(); }
+ void escape_new3();
+ void escape_new3_data() { escape_data(); }
+ void escape_new4();
+ void escape_new4_data() { escape_data(); }
+private:
+ void escape_data();
+};
+
+
+static void verify(const QString &quoted, const QString &expected)
+{
+ if (quoted != expected)
+ qDebug() << "ERROR:" << quoted << expected;
+}
+
+void tst_qregexp::escape_data()
+{
+ QTest::addColumn<QString>("pattern");
+ QTest::addColumn<QString>("expected");
+
+ QTest::newRow("escape 0") << "Hello world" << "Hello world";
+ QTest::newRow("escape 1") << "(Hello world)" << "\\(Hello world\\)";
+ {
+ QString s;
+ for (int i = 0; i < 10; ++i)
+ s += "(escape)";
+ QTest::newRow("escape 10") << s << QRegExp::escape(s);
+ }
+ {
+ QString s;
+ for (int i = 0; i < 100; ++i)
+ s += "(escape)";
+ QTest::newRow("escape 100") << s << QRegExp::escape(s);
+ }
+}
+
+void tst_qregexp::escape_old()
+{
+ QFETCH(QString, pattern);
+ QFETCH(QString, expected);
+
+ QBENCHMARK {
+ static const char meta[] = "$()*+.?[\\]^{|}";
+ QString quoted = pattern;
+ int i = 0;
+
+ while (i < quoted.length()) {
+ if (strchr(meta, quoted.at(i).toLatin1()) != 0)
+ quoted.insert(i++, QLatin1Char('\\'));
+ ++i;
+ }
+
+ verify(quoted, expected);
+ }
+}
+
+void tst_qregexp::escape_new1()
+{
+ QFETCH(QString, pattern);
+ QFETCH(QString, expected);
+
+ QBENCHMARK {
+ QString quoted;
+ const int count = pattern.count();
+ quoted.reserve(count * 2);
+ const QLatin1Char backslash('\\');
+ for (int i = 0; i < count; i++) {
+ switch (pattern.at(i).toLatin1()) {
+ case '$':
+ case '(':
+ case ')':
+ case '*':
+ case '+':
+ case '.':
+ case '?':
+ case '[':
+ case '\\':
+ case ']':
+ case '^':
+ case '{':
+ case '|':
+ case '}':
+ quoted.append(backslash);
+ }
+ quoted.append(pattern.at(i));
+ }
+ verify(quoted, expected);
+ }
+}
+
+void tst_qregexp::escape_new2()
+{
+ QFETCH(QString, pattern);
+ QFETCH(QString, expected);
+
+ QBENCHMARK {
+ int count = pattern.count();
+ const QLatin1Char backslash('\\');
+ QString quoted(count * 2, backslash);
+ const QChar *patternData = pattern.data();
+ QChar *quotedData = quoted.data();
+ int escaped = 0;
+ for ( ; --count >= 0; ++patternData) {
+ const QChar c = *patternData;
+ switch (c.unicode()) {
+ case '$':
+ case '(':
+ case ')':
+ case '*':
+ case '+':
+ case '.':
+ case '?':
+ case '[':
+ case '\\':
+ case ']':
+ case '^':
+ case '{':
+ case '|':
+ case '}':
+ ++escaped;
+ ++quotedData;
+ }
+ *quotedData = c;
+ ++quotedData;
+ }
+ quoted.resize(pattern.size() + escaped);
+
+ verify(quoted, expected);
+ }
+}
+
+void tst_qregexp::escape_new3()
+{
+ QFETCH(QString, pattern);
+ QFETCH(QString, expected);
+
+ QBENCHMARK {
+ QString quoted;
+ const int count = pattern.count();
+ quoted.reserve(count * 2);
+ const QLatin1Char backslash('\\');
+ for (int i = 0; i < count; i++) {
+ switch (pattern.at(i).toLatin1()) {
+ case '$':
+ case '(':
+ case ')':
+ case '*':
+ case '+':
+ case '.':
+ case '?':
+ case '[':
+ case '\\':
+ case ']':
+ case '^':
+ case '{':
+ case '|':
+ case '}':
+ quoted += backslash;
+ }
+ quoted += pattern.at(i);
+ }
+
+ verify(quoted, expected);
+ }
+}
+
+
+static inline bool needsEscaping(int c)
+{
+ switch (c) {
+ case '$':
+ case '(':
+ case ')':
+ case '*':
+ case '+':
+ case '.':
+ case '?':
+ case '[':
+ case '\\':
+ case ']':
+ case '^':
+ case '{':
+ case '|':
+ case '}':
+ return true;
+ }
+ return false;
+}
+
+void tst_qregexp::escape_new4()
+{
+ QFETCH(QString, pattern);
+ QFETCH(QString, expected);
+
+ QBENCHMARK {
+ const int n = pattern.size();
+ const QChar *patternData = pattern.data();
+ // try to prevent copy if no escape is needed
+ int i = 0;
+ for (int i = 0; i != n; ++i) {
+ const QChar c = patternData[i];
+ if (needsEscaping(c.unicode()))
+ break;
+ }
+ if (i == n) {
+ verify(pattern, expected);
+ // no escaping needed, "return pattern" should be done here.
+ return;
+ }
+ const QLatin1Char backslash('\\');
+ QString quoted(n * 2, backslash);
+ QChar *quotedData = quoted.data();
+ for (int j = 0; j != i; ++j)
+ *quotedData++ = *patternData++;
+ int escaped = 0;
+ for (; i != n; ++i) {
+ const QChar c = *patternData;
+ if (needsEscaping(c.unicode())) {
+ ++escaped;
+ ++quotedData;
+ }
+ *quotedData = c;
+ ++quotedData;
+ ++patternData;
+ }
+ quoted.resize(n + escaped);
+ verify(quoted, expected);
+ // "return quoted"
+ }
+}
+QTEST_MAIN(tst_qregexp)
+
+#include "main.moc"
diff --git a/tests/benchmarks/corelib/tools/qregexp/qregexp.pro b/tests/benchmarks/corelib/tools/qregexp/qregexp.pro
new file mode 100644
index 0000000..83d723c
--- /dev/null
+++ b/tests/benchmarks/corelib/tools/qregexp/qregexp.pro
@@ -0,0 +1,12 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_qregexp
+DEPENDPATH += .
+INCLUDEPATH += .
+
+QT -= gui
+
+CONFIG += release
+
+# Input
+SOURCES += main.cpp
diff --git a/tests/benchmarks/corelib/tools/qstring/main.cpp b/tests/benchmarks/corelib/tools/qstring/main.cpp
new file mode 100644
index 0000000..12826eb
--- /dev/null
+++ b/tests/benchmarks/corelib/tools/qstring/main.cpp
@@ -0,0 +1,147 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite 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 Technology Preview License Agreement accompanying
+** this package.
+**
+** 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.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QStringList>
+#include <QFile>
+#include <qtest.h>
+
+#ifdef Q_OS_SYMBIAN
+// In Symbian OS test data is located in applications private dir
+// Application private dir is default serach path for files, so SRCDIR can be set to empty
+#define SRCDIR ""
+#endif
+
+class tst_QString: public QObject
+{
+ Q_OBJECT
+private slots:
+ void equals() const;
+ void equals_data() const;
+ void fromUtf8() const;
+};
+
+void tst_QString::equals() const
+{
+ QFETCH(QString, a);
+ QFETCH(QString, b);
+
+ QBENCHMARK {
+ a == b;
+ }
+}
+
+void tst_QString::equals_data() const
+{
+ static const struct {
+ ushort data[80];
+ int dummy; // just to ensure 4-byte alignment
+ } data = {
+ {
+ 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, // 16
+ 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, // 32
+ 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, // 48
+ 64, 64, 64, 64, 64, 64, 64, 64,
+ 64, 64, 64, 64, 64, 64, 64, 64, // 64
+ 64, 64, 64, 64, 96, 96, 96, 96,
+ 64, 64, 96, 96, 96, 96, 96, 96 // 80
+ }, 0
+ };
+ const QChar *ptr = reinterpret_cast<const QChar *>(data.data);
+
+ QTest::addColumn<QString>("a");
+ QTest::addColumn<QString>("b");
+ QString base = QString::fromRawData(ptr, 64);
+
+ QTest::newRow("different-length") << base << QString::fromRawData(ptr, 4);
+ QTest::newRow("same-string") << base << base;
+ QTest::newRow("same-data") << base << QString::fromRawData(ptr, 64);
+
+ // try to avoid crossing a cache line (that is, at ptr[64])
+ QTest::newRow("aligned-aligned-4n")
+ << QString::fromRawData(ptr, 60) << QString::fromRawData(ptr + 2, 60);
+ QTest::newRow("aligned-unaligned-4n")
+ << QString::fromRawData(ptr, 60) << QString::fromRawData(ptr + 1, 60);
+ QTest::newRow("unaligned-unaligned-4n")
+ << QString::fromRawData(ptr + 1, 60) << QString::fromRawData(ptr + 3, 60);
+
+ QTest::newRow("aligned-aligned-4n+1")
+ << QString::fromRawData(ptr, 61) << QString::fromRawData(ptr + 2, 61);
+ QTest::newRow("aligned-unaligned-4n+1")
+ << QString::fromRawData(ptr, 61) << QString::fromRawData(ptr + 1, 61);
+ QTest::newRow("unaligned-unaligned-4n+1")
+ << QString::fromRawData(ptr + 1, 61) << QString::fromRawData(ptr + 3, 61);
+
+ QTest::newRow("aligned-aligned-4n-1")
+ << QString::fromRawData(ptr, 59) << QString::fromRawData(ptr + 2, 59);
+ QTest::newRow("aligned-unaligned-4n-1")
+ << QString::fromRawData(ptr, 59) << QString::fromRawData(ptr + 1, 59);
+ QTest::newRow("unaligned-unaligned-4n-1")
+ << QString::fromRawData(ptr + 1, 59) << QString::fromRawData(ptr + 3, 59);
+
+ QTest::newRow("aligned-aligned-2n")
+ << QString::fromRawData(ptr, 58) << QString::fromRawData(ptr + 2, 58);
+ QTest::newRow("aligned-unaligned-2n")
+ << QString::fromRawData(ptr, 58) << QString::fromRawData(ptr + 1, 58);
+ QTest::newRow("unaligned-unaligned-2n")
+ << QString::fromRawData(ptr + 1, 58) << QString::fromRawData(ptr + 3, 58);
+}
+
+void tst_QString::fromUtf8() const
+{
+ QFile file(SRCDIR "utf-8.txt");
+ if (!file.open(QFile::ReadOnly)) {
+ qFatal("Cannot open input file");
+ return;
+ }
+ QByteArray data = file.readAll();
+ const char *d = data.constData();
+ int size = data.size();
+
+ QBENCHMARK {
+ QString::fromUtf8(d, size);
+ }
+}
+
+QTEST_MAIN(tst_QString)
+
+#include "main.moc"
diff --git a/tests/benchmarks/corelib/tools/qstring/qstring.pro b/tests/benchmarks/corelib/tools/qstring/qstring.pro
new file mode 100644
index 0000000..2e7c86a
--- /dev/null
+++ b/tests/benchmarks/corelib/tools/qstring/qstring.pro
@@ -0,0 +1,16 @@
+load(qttest_p4)
+TARGET = tst_qstring
+QT -= gui
+SOURCES += main.cpp
+
+wince*:{
+ DEFINES += SRCDIR=\\\"\\\"
+} else:symbian* {
+ addFiles.sources = utf-8.txt
+ addFiles.path = .
+ DEPLOYMENT += addFiles
+ TARGET.EPOCHEAPSIZE="0x100 0x1000000"
+} else {
+ DEFINES += SRCDIR=\\\"$$PWD/\\\"
+}
+
diff --git a/tests/benchmarks/corelib/tools/qstring/utf-8.txt b/tests/benchmarks/corelib/tools/qstring/utf-8.txt
new file mode 100644
index 0000000..a8a58de
--- /dev/null
+++ b/tests/benchmarks/corelib/tools/qstring/utf-8.txt
@@ -0,0 +1,72 @@
+Språk: Norsk
+Γλώσσα: Ελληνικά
+Язык: Русский
+언어 : 한국어
+言語: 日本語
+Langage : Français
+Språk: Norsk
+Γλώσσα: Ελληνικά
+Язык: Русский
+언어 : 한국어
+言語: 日本語
+Langage : Français
+Språk: Norsk
+Γλώσσα: Ελληνικά
+Язык: Русский
+언어 : 한국어
+言語: 日本語
+Langage : Français
+Språk: Norsk
+Γλώσσα: Ελληνικά
+Язык: Русский
+언어 : 한국어
+言語: 日本語
+Langage : Français
+Språk: Norsk
+Γλώσσα: Ελληνικά
+Язык: Русский
+언어 : 한국어
+言語: 日本語
+Langage : Français
+Språk: Norsk
+Γλώσσα: Ελληνικά
+Язык: Русский
+언어 : 한국어
+言語: 日本語
+Langage : Français
+Språk: Norsk
+Γλώσσα: Ελληνικά
+Язык: Русский
+언어 : 한국어
+言語: 日本語
+Langage : Français
+Språk: Norsk
+Γλώσσα: Ελληνικά
+Язык: Русский
+언어 : 한국어
+言語: 日本語
+Langage : Français
+Språk: Norsk
+Γλώσσα: Ελληνικά
+Язык: Русский
+언어 : 한국어
+言語: 日本語
+Langage : Français
+Språk: Norsk
+Γλώσσα: Ελληνικά
+Язык: Русский
+언어 : 한국어
+言語: 日本語
+Langage : Français
+Språk: Norsk
+Γλώσσα: Ελληνικά
+Язык: Русский
+언어 : 한국어
+言語: 日本語
+Langage : Français
+Språk: Norsk
+Γλώσσα: Ελληνικά
+Язык: Русский
+언어 : 한국어
+言語: 日本語
+Langage : Français
diff --git a/tests/benchmarks/corelib/tools/qstringbuilder/main.cpp b/tests/benchmarks/corelib/tools/qstringbuilder/main.cpp
new file mode 100644
index 0000000..9bd146f
--- /dev/null
+++ b/tests/benchmarks/corelib/tools/qstringbuilder/main.cpp
@@ -0,0 +1,464 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite 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 Technology Preview License Agreement accompanying
+** this package.
+**
+** 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.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+// Select one of the scenarios below
+#define SCENARIO 1
+
+#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
+
+
+#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>
+
+#include <string>
+
+#define COMPARE(a, b) QCOMPARE(a, b)
+//#define COMPARE(a, b)
+
+#define SEP(s) qDebug() << "\n\n-------- " s " ---------";
+
+#define LITERAL "some string literal"
+
+class tst_qstringbuilder : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_qstringbuilder()
+ : l1literal(LITERAL),
+ l1string(LITERAL),
+ ba(LITERAL),
+ string(l1string),
+ stdstring(LITERAL),
+ stringref(&string, 2, 10),
+ achar('c'),
+ r2(QLatin1String(LITERAL LITERAL)),
+ r3(QLatin1String(LITERAL LITERAL LITERAL)),
+ r4(QLatin1String(LITERAL LITERAL LITERAL LITERAL)),
+ r5(QLatin1String(LITERAL LITERAL LITERAL LITERAL LITERAL))
+ {}
+
+
+public:
+ enum { N = 10000 };
+
+ int run_traditional()
+ {
+ int s = 0;
+ for (int i = 0; i < N; ++i) {
+#if 0
+ s += QString(l1string + l1string).size();
+ s += QString(l1string + l1string + l1string).size();
+ s += QString(l1string + l1string + l1string + l1string).size();
+ s += QString(l1string + l1string + l1string + l1string + l1string).size();
+#endif
+ s += QString(achar + l1string + achar).size();
+ }
+ return s;
+ }
+
+ int run_builder()
+ {
+ int s = 0;
+ for (int i = 0; i < N; ++i) {
+#if 0
+ 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();
+ }
+ return s;
+ }
+
+private slots:
+
+ void separator_0() {
+ qDebug() << "\nIn each block the QStringBuilder based result appear first "
+ "(with a 'b_' prefix), QStringBased second ('q_' prefix), std::string "
+ "last ('s_' prefix)\n";
+ }
+
+ void separator_1() { SEP("literal + literal (builder first)"); }
+
+ void b_2_l1literal() {
+ 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 q_2_l1string() {
+ QBENCHMARK { r = l1string + l1string; }
+ COMPARE(r, r2);
+ }
+
+
+ void separator_2() { SEP("2 strings"); }
+
+ void b_2_string() {
+ QBENCHMARK { r = string P string; }
+ COMPARE(r, r2);
+ }
+ void q_2_string() {
+ QBENCHMARK { r = string + string; }
+ COMPARE(r, r2);
+ }
+ void s_2_string() {
+ QBENCHMARK { stdr = stdstring + stdstring; }
+ COMPARE(stdr, stdstring + stdstring);
+ }
+
+
+ void separator_2c() { SEP("2 string refs"); }
+
+ void b_2_stringref() {
+ QBENCHMARK { r = stringref % stringref; }
+ COMPARE(r, QString(stringref.toString() + stringref.toString()));
+ }
+ void q_2_stringref() {
+ QBENCHMARK { r = stringref.toString() + stringref.toString(); }
+ COMPARE(r, QString(stringref % stringref));
+ }
+
+
+ void separator_2b() { SEP("3 strings"); }
+
+ void b_3_string() {
+ QBENCHMARK { r = string P string P string; }
+ COMPARE(r, r3);
+ }
+ void q_3_string() {
+ QBENCHMARK { r = string + string + string; }
+ COMPARE(r, r3);
+ }
+ void s_3_string() {
+ QBENCHMARK { stdr = stdstring + stdstring + stdstring; }
+ COMPARE(stdr, stdstring + stdstring + stdstring);
+ }
+
+ void separator_2e() { SEP("4 strings"); }
+
+ void b_4_string() {
+ QBENCHMARK { r = string P string P string P string; }
+ COMPARE(r, r4);
+ }
+ void q_4_string() {
+ QBENCHMARK { r = string + string + string + string; }
+ COMPARE(r, r4);
+ }
+ void s_4_string() {
+ QBENCHMARK { stdr = stdstring + stdstring + stdstring + stdstring; }
+ COMPARE(stdr, stdstring + stdstring + stdstring + stdstring);
+ }
+
+
+
+ void separator_2a() { SEP("string + literal (builder first)"); }
+
+ void b_string_l1literal() {
+ QBENCHMARK { r = string % l1literal; }
+ 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 P l1string; }
+ COMPARE(r, r2);
+ }
+ void q_string_l1literal() {
+ QBENCHMARK { r = string + l1string; }
+ COMPARE(r, r2);
+ }
+ void q_string_l1string() {
+ QBENCHMARK { r = string + l1string; }
+ COMPARE(r, r2);
+ }
+ void s_LITERAL_string() {
+ QBENCHMARK { stdr = LITERAL + stdstring; }
+ COMPARE(stdr, stdstring + stdstring);
+ }
+
+
+ void separator_3() { SEP("3 literals"); }
+
+ void b_3_l1literal() {
+ QBENCHMARK { r = l1literal P l1literal P l1literal; }
+ COMPARE(r, r3);
+ }
+ void q_3_l1string() {
+ QBENCHMARK { r = l1string + l1string + l1string; }
+ COMPARE(r, r3);
+ }
+ void s_3_l1string() {
+ QBENCHMARK { stdr = stdstring + LITERAL + LITERAL; }
+ COMPARE(stdr, stdstring + stdstring + stdstring);
+ }
+
+
+ void separator_4() { SEP("4 literals"); }
+
+ void b_4_l1literal() {
+ QBENCHMARK { r = l1literal P l1literal P l1literal P l1literal; }
+ COMPARE(r, r4);
+ }
+ void q_4_l1string() {
+ QBENCHMARK { r = l1string + l1string + l1string + l1string; }
+ COMPARE(r, r4);
+ }
+
+
+ void separator_5() { SEP("5 literals"); }
+
+ void b_5_l1literal() {
+ QBENCHMARK { r = l1literal P l1literal P l1literal P l1literal P l1literal; }
+ COMPARE(r, r5);
+ }
+
+ void q_5_l1string() {
+ QBENCHMARK { r = l1string + l1string + l1string + l1string + l1string; }
+ COMPARE(r, r5);
+ }
+
+
+ void separator_6() { SEP("4 chars"); }
+
+ void b_string_4_char() {
+ QBENCHMARK { r = string + achar + achar + achar + achar; }
+ COMPARE(r, QString(string P achar P achar P achar P achar));
+ }
+
+ void q_string_4_char() {
+ QBENCHMARK { r = string + achar + achar + achar + achar; }
+ COMPARE(r, QString(string P achar P achar P achar P achar));
+ }
+
+ void s_string_4_char() {
+ QBENCHMARK { stdr = stdstring + 'c' + 'c' + 'c' + 'c'; }
+ COMPARE(stdr, stdstring + 'c' + 'c' + 'c' + 'c');
+ }
+
+
+ void separator_7() { SEP("char + string + char"); }
+
+ void b_char_string_char() {
+ QBENCHMARK { r = achar + string + achar; }
+ COMPARE(r, QString(achar P string P achar));
+ }
+
+ void q_char_string_char() {
+ QBENCHMARK { r = achar + string + achar; }
+ COMPARE(r, QString(achar P string P achar));
+ }
+
+ void s_char_string_char() {
+ QBENCHMARK { stdr = 'c' + stdstring + 'c'; }
+ COMPARE(stdr, 'c' + stdstring + 'c');
+ }
+
+
+ void separator_8() { SEP("string.arg"); }
+
+ void b_string_arg() {
+ const QString pattern = l1string + QString::fromLatin1("%1") + l1string;
+ QBENCHMARK { r = l1literal P string P l1literal; }
+ COMPARE(r, r3);
+ }
+
+ void q_string_arg() {
+ const QString pattern = l1string + QLatin1String("%1") + l1string;
+ QBENCHMARK { r = pattern.arg(string); }
+ COMPARE(r, r3);
+ }
+
+ void q_bytearray_arg() {
+ QByteArray result;
+ QBENCHMARK { result = ba + ba + ba; }
+ }
+
+
+ void separator_9() { SEP("QString::reserve()"); }
+
+ void b_reserve() {
+ QBENCHMARK {
+ r.clear();
+ r = string P string P string P string;
+ }
+ COMPARE(r, r4);
+ }
+ void b_reserve_lit() {
+ QBENCHMARK {
+ r.clear();
+ r = string P l1literal P string P string;
+ }
+ COMPARE(r, r4);
+ }
+ void s_reserve() {
+ QBENCHMARK {
+ r.clear();
+ r.reserve(string.size() + string.size() + string.size() + string.size());
+ r += string;
+ r += string;
+ r += string;
+ r += string;
+ }
+ COMPARE(r, r4);
+ }
+ void s_reserve_lit() {
+ QBENCHMARK {
+ r.clear();
+ //r.reserve(string.size() + qstrlen(l1string.latin1())
+ // + string.size() + string.size());
+ r.reserve(1024);
+ r += string;
+ r += l1string;
+ r += string;
+ r += string;
+ }
+ COMPARE(r, r4);
+ }
+
+private:
+ const QLatin1Literal l1literal;
+ const QLatin1String l1string;
+ const QByteArray ba;
+ const QString string;
+ const std::string stdstring;
+ const QStringRef stringref;
+ const QLatin1Char achar;
+ const QString r2, r3, r4, r5;
+
+ // short cuts for results
+ QString r;
+ std::string stdr;
+};
+
+
+//void operator%(QString, int) {}
+
+int main(int argc, char *argv[])
+{
+ //qDebug() << (QString("xx") * QLatin1String("y")).toString();
+ //42 % 3; // Sanity test, should always work.
+ //QString("x") % 2; // Sanity test, should only compile when the
+ // operator%(QString, int) is visible.
+
+ if (argc == 2 && (QLatin1String(argv[1]) == QLatin1String("--run-builder")
+ || QLatin1String(argv[1]) == QLatin1String("-b"))) {
+ tst_qstringbuilder test;
+ return test.run_builder();
+ }
+
+ if (argc == 2 && (QLatin1String(argv[1]) == QLatin1String("--run-traditional")
+ || QLatin1String(argv[1]) == QLatin1String("-t"))) {
+ tst_qstringbuilder test;
+ return test.run_traditional();
+ }
+
+ if (argc == 1) {
+ QCoreApplication app(argc, argv);
+ QStringList args = app.arguments();
+ tst_qstringbuilder test;
+ return QTest::qExec(&test, argc, argv);
+ }
+
+ qDebug() << "Usage: " << argv[0] << " [--run-builder|-r|--run-traditional|-t]";
+}
+
+
+#include "main.moc"
diff --git a/tests/benchmarks/corelib/tools/qstringbuilder/qstringbuilder.pro b/tests/benchmarks/corelib/tools/qstringbuilder/qstringbuilder.pro
new file mode 100644
index 0000000..79171b4
--- /dev/null
+++ b/tests/benchmarks/corelib/tools/qstringbuilder/qstringbuilder.pro
@@ -0,0 +1,12 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_qstringbuilder
+
+QMAKE_CXXFLAGS += -g
+QMAKE_CFLAGS += -g
+
+QT -= gui
+
+CONFIG += release
+
+SOURCES += main.cpp
diff --git a/tests/benchmarks/corelib/tools/qstringlist/.gitignore b/tests/benchmarks/corelib/tools/qstringlist/.gitignore
new file mode 100644
index 0000000..3e0cdc9
--- /dev/null
+++ b/tests/benchmarks/corelib/tools/qstringlist/.gitignore
@@ -0,0 +1 @@
+tst_qstringlist
diff --git a/tests/benchmarks/corelib/tools/qstringlist/main.cpp b/tests/benchmarks/corelib/tools/qstringlist/main.cpp
new file mode 100644
index 0000000..3fac598
--- /dev/null
+++ b/tests/benchmarks/corelib/tools/qstringlist/main.cpp
@@ -0,0 +1,193 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite 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 Technology Preview License Agreement accompanying
+** this package.
+**
+** 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.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QStringList>
+#include <QtTest>
+
+#include <sstream>
+#include <string>
+#include <vector>
+
+class tst_QStringList: public QObject
+{
+ Q_OBJECT
+
+private slots:
+ void join() const;
+ void join_data() const;
+
+ void split() const;
+ void split_data() const;
+
+ void split_std() const;
+ void split_std_data() const { return split_data(); }
+
+ void split_stdw() const;
+ void split_stdw_data() const { return split_data(); }
+
+ void split_ba() const;
+ void split_ba_data() const { return split_data(); }
+
+private:
+ static QStringList populateList(const int count, const QString &unit);
+ static QString populateString(const int count, const QString &unit);
+};
+
+QStringList tst_QStringList::populateList(const int count, const QString &unit)
+{
+ QStringList retval;
+
+ for (int i = 0; i < count; ++i)
+ retval.append(unit);
+
+ return retval;
+}
+
+QString tst_QStringList::populateString(const int count, const QString &unit)
+{
+ QString retval;
+
+ for (int i = 0; i < count; ++i) {
+ retval.append(unit);
+ retval.append(QLatin1Char(':'));
+ }
+
+ return retval;
+}
+
+void tst_QStringList::join() const
+{
+ QFETCH(QStringList, input);
+ QFETCH(QString, separator);
+
+ QBENCHMARK {
+ input.join(separator);
+ }
+}
+
+void tst_QStringList::join_data() const
+{
+ QTest::addColumn<QStringList>("input");
+ QTest::addColumn<QString>("separator");
+
+ QTest::newRow("")
+ << populateList(100, QLatin1String("unit"))
+ << QString();
+
+ QTest::newRow("")
+ << populateList(1000, QLatin1String("unit"))
+ << QString();
+
+ QTest::newRow("")
+ << populateList(10000, QLatin1String("unit"))
+ << QString();
+
+ QTest::newRow("")
+ << populateList(100000, QLatin1String("unit"))
+ << QString();
+}
+
+void tst_QStringList::split() const
+{
+ QFETCH(QString, input);
+ const QChar splitChar = ':';
+
+ QBENCHMARK {
+ input.split(splitChar);
+ }
+}
+
+void tst_QStringList::split_data() const
+{
+ QTest::addColumn<QString>("input");
+ QString unit = QLatin1String("unit");
+ QTest::newRow("") << populateString(10, unit);
+ QTest::newRow("") << populateString(100, unit);
+ QTest::newRow("") << populateString(1000, unit);
+ QTest::newRow("") << populateString(10000, unit);
+}
+
+void tst_QStringList::split_std() const
+{
+ QFETCH(QString, input);
+ const char split_char = ':';
+ std::string stdinput = input.toStdString();
+
+ QBENCHMARK {
+ std::istringstream split(stdinput);
+ std::vector<std::string> token;
+ for (std::string each;
+ std::getline(split, each, split_char);
+ token.push_back(each))
+ ;
+ }
+}
+
+void tst_QStringList::split_stdw() const
+{
+ QFETCH(QString, input);
+ const wchar_t split_char = ':';
+ std::wstring stdinput = input.toStdWString();
+
+ QBENCHMARK {
+ std::wistringstream split(stdinput);
+ std::vector<std::wstring> token;
+ for (std::wstring each;
+ std::getline(split, each, split_char);
+ token.push_back(each))
+ ;
+ }
+}
+
+void tst_QStringList::split_ba() const
+{
+ QFETCH(QString, input);
+ const char splitChar = ':';
+ QByteArray ba = input.toLatin1();
+
+ QBENCHMARK {
+ ba.split(splitChar);
+ }
+}
+
+QTEST_MAIN(tst_QStringList)
+
+#include "main.moc"
diff --git a/tests/benchmarks/corelib/tools/qstringlist/qstringlist.pro b/tests/benchmarks/corelib/tools/qstringlist/qstringlist.pro
new file mode 100644
index 0000000..11cceb0
--- /dev/null
+++ b/tests/benchmarks/corelib/tools/qstringlist/qstringlist.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+TARGET = tst_qstringlist
+QT -= gui
+SOURCES += main.cpp
+
+symbian: LIBS += -llibpthread
diff --git a/tests/benchmarks/corelib/tools/tools.pro b/tests/benchmarks/corelib/tools/tools.pro
new file mode 100644
index 0000000..12c23fc
--- /dev/null
+++ b/tests/benchmarks/corelib/tools/tools.pro
@@ -0,0 +1,10 @@
+TEMPLATE = subdirs
+SUBDIRS = \
+ containers-associative \
+ containers-sequential \
+ qbytearray \
+ qrect \
+ qregexp \
+ qstring \
+ qstringbuilder \
+ qstringlist