summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/corelib/tools/qhash/outofline.cpp
diff options
context:
space:
mode:
authorRobin Burchell <robin.burchell@collabora.com>2012-01-18 18:02:24 +0200
committerQt by Nokia <qt-info@nokia.com>2012-01-20 12:42:27 +0100
commit8060dd3c42982543b2b5949187fa5b5bb6aeff29 (patch)
tree74c0f26dad9ca8d817ed4d2eb0c8394b17f4dcb0 /tests/benchmarks/corelib/tools/qhash/outofline.cpp
parent03700a293ea59eb9b6f2298d3462dce989f5e5ee (diff)
Add a string hash implementation similar to the one in Java.
This uses a similar runtime to the approach of sampling part of the string, with the benefit that it doesn't reduce the sampling to subsections of the string. Ironically, Java used to only sample parts of the string as well, but found that it produced too many collisions with certain string types, so they moved to use this method. RESULT : tst_QHash::qhash_qt4(): 0.0537 msecs per iteration (total: 110, iterations: 2048) PASS : tst_QHash::qhash_qt4() RESULT : tst_QHash::qhash_faster(): 0.015 msecs per iteration (total: 62, iterations: 4096) PASS : tst_QHash::qhash_faster() RESULT : tst_QHash::javaString(): 0.016 msecs per iteration (total: 66, iterations: 4096) Change-Id: Icb5da341ab6445163f4217650a0bdb3903e50210 Reviewed-by: hjk <qthjk@ovi.com>
Diffstat (limited to 'tests/benchmarks/corelib/tools/qhash/outofline.cpp')
-rw-r--r--tests/benchmarks/corelib/tools/qhash/outofline.cpp13
1 files changed, 13 insertions, 0 deletions
diff --git a/tests/benchmarks/corelib/tools/qhash/outofline.cpp b/tests/benchmarks/corelib/tools/qhash/outofline.cpp
index 11a5f9e733..86e92e1630 100644
--- a/tests/benchmarks/corelib/tools/qhash/outofline.cpp
+++ b/tests/benchmarks/corelib/tools/qhash/outofline.cpp
@@ -87,4 +87,17 @@ uint qHash(const String &str)
return h;
}
+uint qHash(const JavaString &str)
+{
+ const unsigned short *p = (unsigned short *)str.constData();
+ const int len = str.size();
+
+ uint h = 0;
+
+ for (int i = 0; i < len; ++i)
+ h = 31 * h + p[i];
+
+ return h;
+}
+
QT_END_NAMESPACE