summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2011-03-16 12:44:49 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2011-03-22 14:51:40 (GMT)
commitf9370b13165a3919c1beafca5334284ccdd0526a (patch)
tree9f429e0e135620a08085d52b27475ba5699607ad /tests/benchmarks
parente4b41ca2f9aec1be1136decbac323e024f64a176 (diff)
downloadQt-f9370b13165a3919c1beafca5334284ccdd0526a.zip
Qt-f9370b13165a3919c1beafca5334284ccdd0526a.tar.gz
Qt-f9370b13165a3919c1beafca5334284ccdd0526a.tar.bz2
Add a benchmark for QString::fromLatin1
Diffstat (limited to 'tests/benchmarks')
-rw-r--r--tests/benchmarks/corelib/tools/qstring/main.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/tests/benchmarks/corelib/tools/qstring/main.cpp b/tests/benchmarks/corelib/tools/qstring/main.cpp
index a6412a8..cd036e7 100644
--- a/tests/benchmarks/corelib/tools/qstring/main.cpp
+++ b/tests/benchmarks/corelib/tools/qstring/main.cpp
@@ -70,6 +70,8 @@ private slots:
void ucstrncmp_data() const;
void ucstrncmp() const;
void fromUtf8() const;
+ void fromLatin1_data() const;
+ void fromLatin1() const;
};
void tst_QString::equals() const
@@ -1404,6 +1406,40 @@ void tst_QString::fromUtf8() const
}
}
+void tst_QString::fromLatin1_data() const
+{
+ QTest::addColumn<QByteArray>("latin1");
+
+ // make all the strings have the same length
+ QTest::newRow("ascii-only") << QByteArray("HelloWorld");
+ QTest::newRow("ascii+control") << QByteArray("Hello\1\r\n\x7f\t");
+ QTest::newRow("ascii+nul") << QByteArray("a\0zbc\0defg", 10);
+ QTest::newRow("non-ascii") << QByteArray("\x80\xc0\xff\x81\xc1\xfe\x90\xd0\xef\xa0");
+}
+
+void tst_QString::fromLatin1() const
+{
+ QFETCH(QByteArray, latin1);
+
+ while (latin1.length() < 128) {
+ latin1 += latin1;
+ }
+
+ QByteArray copy1 = latin1, copy2 = latin1, copy3 = latin1;
+ copy1.chop(1);
+ copy2.detach();
+ copy3 += latin1; // longer length
+ copy2.clear();
+
+ QBENCHMARK {
+ QString s1 = QString::fromLatin1(latin1);
+ QString s2 = QString::fromLatin1(latin1);
+ QString s3 = QString::fromLatin1(copy1);
+ QString s4 = QString::fromLatin1(copy3);
+ s3 = QString::fromLatin1(copy3);
+ }
+}
+
QTEST_MAIN(tst_QString)
#include "main.moc"