From 3222db0937aaf1ae5681bc124406ec37f550bc7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thorbj=C3=B8rn=20Martsum?= Date: Thu, 10 Jan 2013 19:42:59 +0100 Subject: QVector - removeLast optimize In case somebody uses QVector as a stack, it is not fair to have takeLast, removeLast and pop_back to do way too much work. This is still very slow compared to std::vector::pop_back (mostly due implicit sharing), however it is more than a factor faster than before. Change-Id: I636872675e80c8ca0c8ebc94b04f587a2dcd6d8d Reviewed-by: Thiago Macieira --- tests/benchmarks/corelib/tools/qvector/main.cpp | 37 +++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'tests/benchmarks') diff --git a/tests/benchmarks/corelib/tools/qvector/main.cpp b/tests/benchmarks/corelib/tools/qvector/main.cpp index 1795f2dc6f..3c6defb572 100644 --- a/tests/benchmarks/corelib/tools/qvector/main.cpp +++ b/tests/benchmarks/corelib/tools/qvector/main.cpp @@ -206,6 +206,7 @@ private slots: void qvector_separator() { qWarning() << "QVector results: "; } void qvector_const_read_access(); void qvector_mutable_read_access(); + void qvector_pop_back(); #ifdef TEST_RETURN void qvector_fill_and_return(); #endif @@ -214,6 +215,8 @@ private slots: void stdvector() { qWarning() << "std::vector results: "; } void stdvector_const_read_access(); void stdvector_mutable_read_access(); + void stdvector_pop_back(); + #ifdef TEST_RETURN void stdvector_fill_and_return(); #endif @@ -315,6 +318,24 @@ void tst_QVector::qrawvector_mutable_read_access() } } +void tst_QVector::qvector_pop_back() +{ + const int c1 = 100000; + QVERIFY(N % c1 == 0); + + QVector v; + v.resize(N); + + QBENCHMARK { + for (int i = 0; i < c1; ++i) + v.pop_back(); + if (v.size() == 0) + v.resize(N); + } +} + + + #ifdef TEST_RETURN extern QVector qrawvector_fill_and_return_helper(); @@ -356,6 +377,22 @@ void tst_QVector::stdvector_mutable_read_access() } } +void tst_QVector::stdvector_pop_back() +{ + const int c1 = 100000; + QVERIFY(N % c1 == 0); + + std::vector v; + v.resize(N); + + QBENCHMARK { + for (int i = 0; i < c1; ++i) + v.pop_back(); + if (v.size() == 0) + v.resize(N); + } +} + #ifdef TEST_RETURN extern std::vector stdvector_fill_and_return_helper(); -- cgit v1.2.3