summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/corelib/tools/qhash/main.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmarks/corelib/tools/qhash/main.cpp')
-rw-r--r--tests/benchmarks/corelib/tools/qhash/main.cpp105
1 files changed, 62 insertions, 43 deletions
diff --git a/tests/benchmarks/corelib/tools/qhash/main.cpp b/tests/benchmarks/corelib/tools/qhash/main.cpp
index 18138cbd47..67396ffd57 100644
--- a/tests/benchmarks/corelib/tools/qhash/main.cpp
+++ b/tests/benchmarks/corelib/tools/qhash/main.cpp
@@ -54,72 +54,91 @@ class tst_QHash : public QObject
Q_OBJECT
private slots:
+ void initTestCase();
void qhash_qt4_data() { data(); }
void qhash_qt4();
- void qhash_faster_data() { data(); }
- void qhash_faster();
void javaString_data() { data(); }
void javaString();
private:
void data();
+
+ QStringList smallFilePaths;
+ QStringList uuids;
+ QStringList dict;
+ QStringList numbers;
};
///////////////////// QHash /////////////////////
-void tst_QHash::data()
-{
- QTest::addColumn<QStringList>("items");
- static QStringList smallFilePaths;
-
- {
- // small list of file paths
- if (smallFilePaths.isEmpty()) {
- QFile smallPathsData("paths_small_data.txt");
- QVERIFY(smallPathsData.open(QIODevice::ReadOnly));
- smallFilePaths = QString::fromLatin1(smallPathsData.readAll()).split(QLatin1Char('\n'));
- Q_ASSERT(!smallFilePaths.isEmpty());
- }
+#include <QDebug>
- QTest::newRow("paths-small") << smallFilePaths;
- }
-
- {
- // list of UUIDs
- static QStringList uuids;
- if (uuids.isEmpty()) {
- // guaranteed to be completely random, generated by http://xkcd.com/221/
- QUuid ns = QUuid("{f43d2ef3-2fe9-4563-a6f5-5a0100c2d699}");
- uuids.reserve(smallFilePaths.size());
-
- foreach (const QString &path, smallFilePaths)
- uuids.append(QUuid::createUuidV5(ns, path).toString());
+void tst_QHash::initTestCase()
+{
+ // small list of file paths
+ QFile smallPathsData("paths_small_data.txt");
+ QVERIFY(smallPathsData.open(QIODevice::ReadOnly));
+ smallFilePaths = QString::fromLatin1(smallPathsData.readAll()).split(QLatin1Char('\n'));
+ QVERIFY(!smallFilePaths.isEmpty());
+
+ // list of UUIDs
+ // guaranteed to be completely random, generated by http://xkcd.com/221/
+ QUuid ns = QUuid("{f43d2ef3-2fe9-4563-a6f5-5a0100c2d699}");
+ uuids.reserve(smallFilePaths.size());
+
+ foreach (const QString &path, smallFilePaths)
+ uuids.append(QUuid::createUuidV5(ns, path).toString());
+
+
+ // lots of strings with alphabetical characters, vaguely reminiscent of
+ // a dictionary.
+ //
+ // this programatically generates a series like:
+ // AAAAAA
+ // AAAAAB
+ // AAAAAC
+ // ...
+ // AAAAAZ
+ // AAAABZ
+ // ...
+ // AAAAZZ
+ // AAABZZ
+ QByteArray id("AAAAAAA");
+
+ if (dict.isEmpty()) {
+ for (int i = id.length() - 1; i > 0;) {
+ dict.append(id);
+ char c = id.at(i);
+ id[i] = ++c;
+
+ if (c == 'Z') {
+ // wrap to next digit
+ i--;
+ id[i] = 'A';
+ }
}
-
- QTest::newRow("uuids-list") << uuids;
}
+ // string versions of numbers.
+ for (int i = 5000000; i < 5005001; ++i)
+ numbers.append(QString::number(i));
}
-void tst_QHash::qhash_qt4()
+void tst_QHash::data()
{
- QFETCH(QStringList, items);
- QStringList realitems = items; // for copy/paste ease between benchmarks
- QHash<QString, int> hash;
-
- QBENCHMARK {
- for (int i = 0, n = realitems.size(); i != n; ++i) {
- hash[realitems.at(i)] = i;
- }
- }
+ QTest::addColumn<QStringList>("items");
+ QTest::newRow("paths-small") << smallFilePaths;
+ QTest::newRow("uuids-list") << uuids;
+ QTest::newRow("dictionary") << dict;
+ QTest::newRow("numbers") << numbers;
}
-void tst_QHash::qhash_faster()
+void tst_QHash::qhash_qt4()
{
QFETCH(QStringList, items);
- QHash<String, int> hash;
+ QHash<Qt4String, int> hash;
- QList<String> realitems;
+ QList<Qt4String> realitems;
foreach (const QString &s, items)
realitems.append(s);