From 250b69ace47923b51aaeaaea39e0ffc638fa4b4a Mon Sep 17 00:00:00 2001 From: Andrei Golubev Date: Wed, 4 Nov 2020 17:58:12 +0100 Subject: Fix QArrayDataOps generic and relocatable emplace() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Emplace() implemented with std::rotate is just awful on my system (Ubuntu 18.04 GCC 7.5.0). Custom code is much faster, so go for it. Cannot really use insert() code, which is also fast, because it doesn't forward-reference values but copies them always Changes in performance (approximately) for emplacing 100k elements into the middle: Complex 7600ms -> 1700ms Movable 7600ms -> 200ms Task-number: QTBUG-86583 Change-Id: If883c9b8498a89e757f3806aea11f8fd3aa3c709 Reviewed-by: MÃ¥rten Nordheim Reviewed-by: Lars Knoll Reviewed-by: Thiago Macieira --- tests/benchmarks/corelib/tools/qlist/main.cpp | 100 ++++++++++++++++++++------ 1 file changed, 80 insertions(+), 20 deletions(-) (limited to 'tests/benchmarks/corelib/tools/qlist/main.cpp') diff --git a/tests/benchmarks/corelib/tools/qlist/main.cpp b/tests/benchmarks/corelib/tools/qlist/main.cpp index 716a3061ae..223e1603e1 100644 --- a/tests/benchmarks/corelib/tools/qlist/main.cpp +++ b/tests/benchmarks/corelib/tools/qlist/main.cpp @@ -184,11 +184,11 @@ private Q_SLOTS: void appendPrependOne_complex_data() const { commonBenchmark_data(); } void appendPrependOne_QString_data() const { commonBenchmark_data(); } - void appendPrependOne_int() const { midInsertOne_impl(); } - void appendPrependOne_primitive() const { midInsertOne_impl(); } - void appendPrependOne_movable() const { midInsertOne_impl(); } - void appendPrependOne_complex() const { midInsertOne_impl(); } - void appendPrependOne_QString() const { midInsertOne_impl(); } + void appendPrependOne_int() const { appendPrependOne_impl(); } + void appendPrependOne_primitive() const { appendPrependOne_impl(); } + void appendPrependOne_movable() const { appendPrependOne_impl(); } + void appendPrependOne_complex() const { appendPrependOne_impl(); } + void appendPrependOne_QString() const { appendPrependOne_impl(); } // prepend half elements, then appen another half: void prependAppendHalvesOne_int_data() const { commonBenchmark_data(); } @@ -197,11 +197,27 @@ private Q_SLOTS: void prependAppendHalvesOne_complex_data() const { commonBenchmark_data(); } void prependAppendHalvesOne_QString_data() const { commonBenchmark_data(); } - void prependAppendHalvesOne_int() const { midInsertOne_impl(); } - void prependAppendHalvesOne_primitive() const { midInsertOne_impl(); } - void prependAppendHalvesOne_movable() const { midInsertOne_impl(); } - void prependAppendHalvesOne_complex() const { midInsertOne_impl(); } - void prependAppendHalvesOne_QString() const { midInsertOne_impl(); } + void prependAppendHalvesOne_int() const { prependAppendHalvesOne_impl(); } + void prependAppendHalvesOne_primitive() const + { + prependAppendHalvesOne_impl(); + } + void prependAppendHalvesOne_movable() const { prependAppendHalvesOne_impl(); } + void prependAppendHalvesOne_complex() const { prependAppendHalvesOne_impl(); } + void prependAppendHalvesOne_QString() const { prependAppendHalvesOne_impl(); } + + // emplace in middle 1 element: + void midEmplaceOne_int_data() const { commonBenchmark_data(); } + void midEmplaceOne_primitive_data() const { commonBenchmark_data(); } + void midEmplaceOne_movable_data() const { commonBenchmark_data(); } + void midEmplaceOne_complex_data() const { commonBenchmark_data(); } + void midEmplaceOne_QString_data() const { commonBenchmark_data(); } + + void midEmplaceOne_int() const { midEmplaceOne_impl(); } + void midEmplaceOne_primitive() const { midEmplaceOne_impl(); } + void midEmplaceOne_movable() const { midEmplaceOne_impl(); } + void midEmplaceOne_complex() const { midEmplaceOne_impl(); } + void midEmplaceOne_QString() const { midEmplaceOne_impl(); } // For 5.15 we also want to compare against QVector #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) @@ -251,11 +267,14 @@ private Q_SLOTS: void qvector_appendPrependOne_complex_data() const { commonBenchmark_data(); } void qvector_appendPrependOne_QString_data() const { commonBenchmark_data(); } - void qvector_appendPrependOne_int() const { midInsertOne_impl(); } - void qvector_appendPrependOne_primitive() const { midInsertOne_impl(); } - void qvector_appendPrependOne_movable() const { midInsertOne_impl(); } - void qvector_appendPrependOne_complex() const { midInsertOne_impl(); } - void qvector_appendPrependOne_QString() const { midInsertOne_impl(); } + void qvector_appendPrependOne_int() const { appendPrependOne_impl(); } + void qvector_appendPrependOne_primitive() const + { + appendPrependOne_impl(); + } + void qvector_appendPrependOne_movable() const { appendPrependOne_impl(); } + void qvector_appendPrependOne_complex() const { appendPrependOne_impl(); } + void qvector_appendPrependOne_QString() const { appendPrependOne_impl(); } // prepend half elements, then appen another half: void qvector_prependAppendHalvesOne_int_data() const { commonBenchmark_data(); } @@ -267,14 +286,36 @@ private Q_SLOTS: void qvector_prependAppendHalvesOne_complex_data() const { commonBenchmark_data(); } void qvector_prependAppendHalvesOne_QString_data() const { commonBenchmark_data(); } - void qvector_prependAppendHalvesOne_int() const { midInsertOne_impl(); } + void qvector_prependAppendHalvesOne_int() const { prependAppendHalvesOne_impl(); } void qvector_prependAppendHalvesOne_primitive() const { - midInsertOne_impl(); + prependAppendHalvesOne_impl(); + } + void qvector_prependAppendHalvesOne_movable() const + { + prependAppendHalvesOne_impl(); + } + void qvector_prependAppendHalvesOne_complex() const + { + prependAppendHalvesOne_impl(); + } + void qvector_prependAppendHalvesOne_QString() const + { + prependAppendHalvesOne_impl(); } - void qvector_prependAppendHalvesOne_movable() const { midInsertOne_impl(); } - void qvector_prependAppendHalvesOne_complex() const { midInsertOne_impl(); } - void qvector_prependAppendHalvesOne_QString() const { midInsertOne_impl(); } + + // emplace in middle 1 element: + void qvector_midEmplaceOne_int_data() const { commonBenchmark_data(); } + void qvector_midEmplaceOne_primitive_data() const { commonBenchmark_data(); } + void qvector_midEmplaceOne_movable_data() const { commonBenchmark_data(); } + void qvector_midEmplaceOne_complex_data() const { commonBenchmark_data(); } + void qvector_midEmplaceOne_QString_data() const { commonBenchmark_data(); } + + void qvector_midEmplaceOne_int() const { midEmplaceOne_impl(); } + void qvector_midEmplaceOne_primitive() const { midEmplaceOne_impl(); } + void qvector_midEmplaceOne_movable() const { midEmplaceOne_impl(); } + void qvector_midEmplaceOne_complex() const { midEmplaceOne_impl(); } + void qvector_midEmplaceOne_QString() const { midEmplaceOne_impl(); } #endif private: @@ -295,6 +336,9 @@ private: template typename, typename> void prependAppendHalvesOne_impl() const; + + template typename, typename> + void midEmplaceOne_impl() const; }; template @@ -495,6 +539,22 @@ void tst_QList::prependAppendHalvesOne_impl() const } } +template typename Container, typename T> +void tst_QList::midEmplaceOne_impl() const +{ + QFETCH(int, elemCount); + constexpr auto getValue = []() { return T {}; }; + + QBENCHMARK { + Container container; + auto lvalue = getValue(); + + for (int i = 0; i < elemCount; ++i) { + container.emplace(container.size() / 2, lvalue); + } + } +} + QTEST_APPLESS_MAIN(tst_QList) #include "main.moc" -- cgit v1.2.3