summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks
diff options
context:
space:
mode:
authorThorbjørn Lund Martsum <tmartsum@gmail.com>2012-10-05 15:58:56 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-03-06 18:56:17 +0100
commitca6a4258d0816b3608295eb40ac89cfd82bab5bd (patch)
treeec23f4d7dcb304fd9b0702efbf01672c266d5aa5 /tests/benchmarks
parent49a2ec05b43b49d06dba8c6909c9df8d308e127d (diff)
QMap - add insert overload that provide a hint
This adds a fast insert on QMap when providing a correct hint. Change-Id: I256bba342932c1d4f24c6e65074e1bf47b519537 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Lars Knoll <lars.knoll@digia.com>
Diffstat (limited to 'tests/benchmarks')
-rw-r--r--tests/benchmarks/corelib/tools/qmap/main.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/tests/benchmarks/corelib/tools/qmap/main.cpp b/tests/benchmarks/corelib/tools/qmap/main.cpp
index e0bd994967..53b2a90fab 100644
--- a/tests/benchmarks/corelib/tools/qmap/main.cpp
+++ b/tests/benchmarks/corelib/tools/qmap/main.cpp
@@ -64,6 +64,14 @@ private slots:
void iterator_begin();
void ctorStdMap();
+
+ void insertion_int_intx();
+ void insertion_int_int_with_hint1();
+ void insertion_int_int2();
+ void insertion_int_int_with_hint2();
+
+ void insertion_string_int2();
+ void insertion_string_int2_hint();
};
@@ -76,6 +84,44 @@ void tst_QMap::insertion_int_int()
}
}
+void tst_QMap::insertion_int_intx()
+{
+ // This is the same test - but executed later.
+ // The results in the beginning of the test seems to be a somewhat inaccurate.
+ QMap<int, int> map;
+ QBENCHMARK {
+ for (int i = 0; i < 100000; ++i)
+ map.insert(i, i);
+ }
+}
+
+void tst_QMap::insertion_int_int_with_hint1()
+{
+ QMap<int, int> map;
+ QBENCHMARK {
+ for (int i = 0; i < 100000; ++i)
+ map.insert(map.constEnd(), i, i);
+ }
+}
+
+void tst_QMap::insertion_int_int2()
+{
+ QMap<int, int> map;
+ QBENCHMARK {
+ for (int i = 100000; i >= 0; --i)
+ map.insert(i, i);
+ }
+}
+
+void tst_QMap::insertion_int_int_with_hint2()
+{
+ QMap<int, int> map;
+ QBENCHMARK {
+ for (int i = 100000; i >= 0; --i)
+ map.insert(map.constBegin(), i, i);
+ }
+}
+
void tst_QMap::insertion_int_string()
{
QMap<int, QString> map;
@@ -203,6 +249,38 @@ void tst_QMap::ctorStdMap()
}
}
+class XString : public QString
+{
+public:
+ bool operator < (const XString& x) const // an expensive operator <
+ {
+ return toInt() < x.toInt();
+ }
+};
+
+void tst_QMap::insertion_string_int2()
+{
+ QMap<XString, int> map;
+ QBENCHMARK {
+ for (int i = 1; i < 5000; ++i) {
+ XString str;
+ str.setNum(i);
+ map.insert(str, i);
+ }
+ }
+}
+
+void tst_QMap::insertion_string_int2_hint()
+{
+ QMap<XString, int> map;
+ QBENCHMARK {
+ for (int i = 1; i < 5000; ++i) {
+ XString str;
+ str.setNum(i);
+ map.insert(map.end(), str, i);
+ }
+ }
+}
QTEST_MAIN(tst_QMap)