summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2009-05-18 21:24:03 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2009-05-22 12:17:39 (GMT)
commit7c848d093e2ce12528d8af435a6e10bc0e28f1e3 (patch)
treee2933852f4f41b4d3b2a93765a73240e73a27b63 /tests/benchmarks
parenta97862318a6b3f72a05a3e66ebcf5f0e455bb42a (diff)
downloadQt-7c848d093e2ce12528d8af435a6e10bc0e28f1e3.zip
Qt-7c848d093e2ce12528d8af435a6e10bc0e28f1e3.tar.gz
Qt-7c848d093e2ce12528d8af435a6e10bc0e28f1e3.tar.bz2
Add a benchmark for QString::operator==
Reviewed-By: Bradley T. Hughes
Diffstat (limited to 'tests/benchmarks')
-rw-r--r--tests/benchmarks/qstring/main.cpp104
-rw-r--r--tests/benchmarks/qstring/qstring.pro4
2 files changed, 108 insertions, 0 deletions
diff --git a/tests/benchmarks/qstring/main.cpp b/tests/benchmarks/qstring/main.cpp
new file mode 100644
index 0000000..c7962bd
--- /dev/null
+++ b/tests/benchmarks/qstring/main.cpp
@@ -0,0 +1,104 @@
+/****************************************************************************
+**
+** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** Contact: Qt Software Information (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 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 <QStringList>
+#include <qtest.h>
+
+class tst_QString: public QObject
+{
+ Q_OBJECT
+private slots:
+ void equals() const;
+ void equals_data() 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, 64, 64, 64, 64,
+ 96, 96, 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);
+
+ // don't use length > 64, since that crosses a cache line
+ QTest::newRow("aligned-odd")
+ << QString::fromRawData(ptr, 63) << QString::fromRawData(ptr + 2, 63);
+ QTest::newRow("aligned-even")
+ << QString::fromRawData(ptr, 64) << QString::fromRawData(ptr + 2, 64);
+ QTest::newRow("unaligned-even")
+ << QString::fromRawData(ptr, 63) << QString::fromRawData(ptr + 1, 63);
+ QTest::newRow("unaligned-odd")
+ << QString::fromRawData(ptr, 64) << QString::fromRawData(ptr + 1, 64);
+}
+
+QTEST_MAIN(tst_QString)
+
+#include "main.moc"
diff --git a/tests/benchmarks/qstring/qstring.pro b/tests/benchmarks/qstring/qstring.pro
new file mode 100644
index 0000000..74423e7
--- /dev/null
+++ b/tests/benchmarks/qstring/qstring.pro
@@ -0,0 +1,4 @@
+load(qttest_p4)
+TARGET = tst_qstring
+QT -= gui
+SOURCES += main.cpp