summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/benchmarks/qstringbuilder/main.cpp59
-rw-r--r--tests/benchmarks/qstringbuilder/qstringbuilder.pro6
2 files changed, 50 insertions, 15 deletions
diff --git a/tests/benchmarks/qstringbuilder/main.cpp b/tests/benchmarks/qstringbuilder/main.cpp
index ba5cfe0a76..d5a538f521 100644
--- a/tests/benchmarks/qstringbuilder/main.cpp
+++ b/tests/benchmarks/qstringbuilder/main.cpp
@@ -1,12 +1,15 @@
+#include "qstringbuilder.h"
+
#include <QDebug>
#include <QString>
-#include "../../../src/libs/utils/qstringbuilder.h"
-
#include <qtest.h>
+#define COMPARE(a, b) QCOMPARE(a, b)
+//#define COMPARE(a, b)
+
class tst_qstringbuilder : public QObject
{
Q_OBJECT
@@ -20,14 +23,18 @@ private slots:
void b_2_l1literal();
void b_3_l1literal();
void b_4_l1literal();
+ void b_5_l1literal();
void b_string_4_char();
+ void b_char_string_char();
// QString based for comparison
void s_separator() { qDebug() << "\n-------- QString based ---------"; }
void s_2_l1string();
void s_3_l1string();
void s_4_l1string();
+ void s_5_l1string();
void s_string_4_char();
+ void s_char_string_char();
private:
const QLatin1Literal l1literal;
@@ -48,28 +55,42 @@ void tst_qstringbuilder::b_2_l1literal()
{
QString result;
QBENCHMARK { result = l1literal % l1literal; }
- QCOMPARE(result, l1string + l1string);
+ COMPARE(result, l1string + l1string);
}
void tst_qstringbuilder::b_3_l1literal()
{
QString result;
QBENCHMARK { result = l1literal % l1literal % l1literal; }
- QCOMPARE(result, l1string + l1string + l1string);
+ COMPARE(result, l1string + l1string + l1string);
}
void tst_qstringbuilder::b_4_l1literal()
{
QString result;
QBENCHMARK { result = l1literal % l1literal % l1literal % l1literal; }
- QCOMPARE(result, l1string + l1string + l1string + l1string);
+ COMPARE(result, l1string + l1string + l1string + l1string);
+}
+
+void tst_qstringbuilder::b_5_l1literal()
+{
+ QString result;
+ QBENCHMARK { result = l1literal % l1literal % l1literal % l1literal %l1literal; }
+ COMPARE(result, l1string + l1string + l1string + l1string + l1string);
}
void tst_qstringbuilder::b_string_4_char()
{
QString result;
- QBENCHMARK { result = string + achar + achar + achar; }
- QCOMPARE(result, QString(string % achar % achar % achar));
+ QBENCHMARK { result = string + achar + achar + achar + achar; }
+ COMPARE(result, QString(string % achar % achar % achar % achar));
+}
+
+void tst_qstringbuilder::b_char_string_char()
+{
+ QString result;
+ QBENCHMARK { result = achar + string + achar; }
+ COMPARE(result, QString(achar % string % achar));
}
@@ -77,28 +98,42 @@ void tst_qstringbuilder::s_2_l1string()
{
QString result;
QBENCHMARK { result = l1string + l1string; }
- QCOMPARE(result, QString(l1literal % l1literal));
+ COMPARE(result, QString(l1literal % l1literal));
}
void tst_qstringbuilder::s_3_l1string()
{
QString result;
QBENCHMARK { result = l1string + l1string + l1string; }
- QCOMPARE(result, QString(l1literal % l1literal % l1literal));
+ COMPARE(result, QString(l1literal % l1literal % l1literal));
}
void tst_qstringbuilder::s_4_l1string()
{
QString result;
QBENCHMARK { result = l1string + l1string + l1string + l1string; }
- QCOMPARE(result, QString(l1literal % l1literal % l1literal % l1literal));
+ COMPARE(result, QString(l1literal % l1literal % l1literal % l1literal));
+}
+
+void tst_qstringbuilder::s_5_l1string()
+{
+ QString result;
+ QBENCHMARK { result = l1string + l1string + l1string + l1string + l1string; }
+ COMPARE(result, QString(l1literal % l1literal % l1literal % l1literal % l1literal));
}
void tst_qstringbuilder::s_string_4_char()
{
QString result;
- QBENCHMARK { result = string + achar + achar + achar; }
- QCOMPARE(result, QString(string % achar % achar % achar));
+ QBENCHMARK { result = string + achar + achar + achar + achar; }
+ COMPARE(result, QString(string % achar % achar % achar % achar));
+}
+
+void tst_qstringbuilder::s_char_string_char()
+{
+ QString result;
+ QBENCHMARK { result = achar + string + achar; }
+ COMPARE(result, QString(achar % string % achar));
}
QTEST_MAIN(tst_qstringbuilder)
diff --git a/tests/benchmarks/qstringbuilder/qstringbuilder.pro b/tests/benchmarks/qstringbuilder/qstringbuilder.pro
index 81c42bc565..578ca1d3ac 100644
--- a/tests/benchmarks/qstringbuilder/qstringbuilder.pro
+++ b/tests/benchmarks/qstringbuilder/qstringbuilder.pro
@@ -1,12 +1,12 @@
load(qttest_p4)
TEMPLATE = app
TARGET = tst_qstringbuilder
-DEPENDPATH += .
-INCLUDEPATH += .
+STRINGBUILDERDIR = ../../../src/libs/utils
+INCLUDEPATH += $$STRINGBUILDERDIR
QT -= gui
CONFIG += release
# Input
-SOURCES += main.cpp
+SOURCES += main.cpp $$STRINGBUILDERDIR/qstringbuilder.cpp