From 1806ea8dd9c5849ea70389d5c3baf66137242d8e Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Fri, 20 Jan 2012 01:54:43 +0200 Subject: [PATCH] Add the capability to use multiple data sources for qhash benchmark. More data sources to be added in followup commits. Change-Id: I0393119b36ac5d88fc2c5c8d46b000d13d5ca996 Reviewed-by: Richard J. Moore --- tests/benchmarks/corelib/tools/qhash/main.cpp | 51 +++++++++++-------- .../qhash/{data.txt => paths_small_data.txt} | 0 2 files changed, 31 insertions(+), 20 deletions(-) rename tests/benchmarks/corelib/tools/qhash/{data.txt => paths_small_data.txt} (100%) diff --git a/tests/benchmarks/corelib/tools/qhash/main.cpp b/tests/benchmarks/corelib/tools/qhash/main.cpp index 412f071a99..f9aec58485 100644 --- a/tests/benchmarks/corelib/tools/qhash/main.cpp +++ b/tests/benchmarks/corelib/tools/qhash/main.cpp @@ -54,12 +54,15 @@ class tst_QHash : public QObject Q_OBJECT private slots: + void qhash_qt4_data() { data(); } void qhash_qt4(); + void qhash_faster_data() { data(); } void qhash_faster(); + void javaString_data() { data(); } void javaString(); private: - QString data(); + void data(); }; const int N = 1000000; @@ -67,49 +70,57 @@ extern double s; ///////////////////// QHash ///////////////////// -QString tst_QHash::data() +void tst_QHash::data() { - QFile file("data.txt"); - file.open(QIODevice::ReadOnly); - return QString::fromLatin1(file.readAll()); + QFile smallPathsData("paths_small_data.txt"); + smallPathsData.open(QIODevice::ReadOnly); + + QTest::addColumn("items"); + QTest::newRow("paths-small") + << QString::fromLatin1(smallPathsData.readAll()).split(QLatin1Char('\n')); } void tst_QHash::qhash_qt4() { - QStringList items = data().split(QLatin1Char('\n')); + QFETCH(QStringList, items); + QStringList realitems = items; // for copy/paste ease between benchmarks QHash hash; - + QBENCHMARK { - for (int i = 0, n = items.size(); i != n; ++i) { - hash[items.at(i)] = i; + for (int i = 0, n = realitems.size(); i != n; ++i) { + hash[realitems.at(i)] = i; } } } void tst_QHash::qhash_faster() { - QList items; - foreach (const QString &s, data().split(QLatin1Char('\n'))) - items.append(s); + QFETCH(QStringList, items); QHash hash; - + + QList realitems; + foreach (const QString &s, items) + realitems.append(s); + QBENCHMARK { - for (int i = 0, n = items.size(); i != n; ++i) { - hash[items.at(i)] = i; + for (int i = 0, n = realitems.size(); i != n; ++i) { + hash[realitems.at(i)] = i; } } } void tst_QHash::javaString() { - QList items; - foreach (const QString &s, data().split(QLatin1Char('\n'))) - items.append(s); + QFETCH(QStringList, items); QHash hash; + QList realitems; + foreach (const QString &s, items) + realitems.append(s); + QBENCHMARK { - for (int i = 0, n = items.size(); i != n; ++i) { - hash[items.at(i)] = i; + for (int i = 0, n = realitems.size(); i != n; ++i) { + hash[realitems.at(i)] = i; } } } diff --git a/tests/benchmarks/corelib/tools/qhash/data.txt b/tests/benchmarks/corelib/tools/qhash/paths_small_data.txt similarity index 100% rename from tests/benchmarks/corelib/tools/qhash/data.txt rename to tests/benchmarks/corelib/tools/qhash/paths_small_data.txt