From 1f4804452c05c57308979bf090305c7c882f92c9 Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Tue, 28 Feb 2012 20:56:14 +0100 Subject: Copy Qt 4's QString hash algorithm. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We must do this the same way we do all other hash algorithms for fair comparison, as otherwise, the call to the PLT unfairly penalises QHash's results, as it's in a different shared object. Change-Id: I69c891f5a97dcccdfcfbdbf32796f86242a42963 Reviewed-by: João Abecasis Reviewed-by: Thiago Macieira --- tests/benchmarks/corelib/tools/qhash/main.cpp | 7 +++++-- tests/benchmarks/corelib/tools/qhash/main.h | 11 +++++++++++ tests/benchmarks/corelib/tools/qhash/outofline.cpp | 18 ++++++++++++++++-- 3 files changed, 32 insertions(+), 4 deletions(-) (limited to 'tests/benchmarks/corelib/tools') diff --git a/tests/benchmarks/corelib/tools/qhash/main.cpp b/tests/benchmarks/corelib/tools/qhash/main.cpp index 7a871b455c..62384fbaa7 100644 --- a/tests/benchmarks/corelib/tools/qhash/main.cpp +++ b/tests/benchmarks/corelib/tools/qhash/main.cpp @@ -138,8 +138,11 @@ void tst_QHash::data() void tst_QHash::qhash_qt4() { QFETCH(QStringList, items); - QStringList realitems = items; // for copy/paste ease between benchmarks - QHash hash; + QHash hash; + + QList realitems; + foreach (const QString &s, items) + realitems.append(s); QBENCHMARK { for (int i = 0, n = realitems.size(); i != n; ++i) { diff --git a/tests/benchmarks/corelib/tools/qhash/main.h b/tests/benchmarks/corelib/tools/qhash/main.h index c4cf94e190..3d193b5e40 100644 --- a/tests/benchmarks/corelib/tools/qhash/main.h +++ b/tests/benchmarks/corelib/tools/qhash/main.h @@ -41,6 +41,17 @@ #include +struct Qt4String : QString +{ + Qt4String() {} + Qt4String(const QString &s) : QString(s) {} +}; + +QT_BEGIN_NAMESPACE +uint qHash(const Qt4String &); +QT_END_NAMESPACE + + struct String : QString { String() {} diff --git a/tests/benchmarks/corelib/tools/qhash/outofline.cpp b/tests/benchmarks/corelib/tools/qhash/outofline.cpp index 162c604a35..8adaa0a04f 100644 --- a/tests/benchmarks/corelib/tools/qhash/outofline.cpp +++ b/tests/benchmarks/corelib/tools/qhash/outofline.cpp @@ -41,6 +41,22 @@ #include "main.h" +QT_BEGIN_NAMESPACE + +uint qHash(const Qt4String &str) +{ + int n = str.length(); + const QChar *p = str.unicode(); + uint h = 0; + + while (n--) { + h = (h << 4) + (*p++).unicode(); + h ^= (h & 0xf0000000) >> 23; + h &= 0x0fffffff; + } + return h; +} + static void doHash(const unsigned short *p, uint &h) { #if 1 @@ -67,8 +83,6 @@ static void doHash(const unsigned short *p, uint &h) #endif } -QT_BEGIN_NAMESPACE - uint qHash(const String &str) { const unsigned short *p = (unsigned short *)str.constData(); -- cgit v1.2.3