From ca6a4258d0816b3608295eb40ac89cfd82bab5bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= Date: Fri, 5 Oct 2012 15:58:56 +0200 Subject: 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 Reviewed-by: Lars Knoll --- tests/benchmarks/corelib/tools/qmap/main.cpp | 78 ++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) (limited to 'tests/benchmarks/corelib/tools') 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 map; + QBENCHMARK { + for (int i = 0; i < 100000; ++i) + map.insert(i, i); + } +} + +void tst_QMap::insertion_int_int_with_hint1() +{ + QMap map; + QBENCHMARK { + for (int i = 0; i < 100000; ++i) + map.insert(map.constEnd(), i, i); + } +} + +void tst_QMap::insertion_int_int2() +{ + QMap map; + QBENCHMARK { + for (int i = 100000; i >= 0; --i) + map.insert(i, i); + } +} + +void tst_QMap::insertion_int_int_with_hint2() +{ + QMap map; + QBENCHMARK { + for (int i = 100000; i >= 0; --i) + map.insert(map.constBegin(), i, i); + } +} + void tst_QMap::insertion_int_string() { QMap 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 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 map; + QBENCHMARK { + for (int i = 1; i < 5000; ++i) { + XString str; + str.setNum(i); + map.insert(map.end(), str, i); + } + } +} QTEST_MAIN(tst_QMap) -- cgit v1.2.3