Details
-
Suggestion
-
Resolution: Done
-
P3: Somewhat important
-
None
-
None
-
None
-
Clang 3.4 and GCC 4.6
Qt 5.3.2 (Clang)
Qt 5.3.1 (GCC)
Description
I have run the attached benchmark to compare the performance of foreach and range-based for using QVector and QHash with clang and gcc for varying container sizes. Example results for container sizes 5, 5000 and 5'000'000 are also attached.
I think the results suggest that Qt documentation on containers should discuss foreach and range-based loop similar to how different threading solutions are discussed at considerable detail. (http://qt-project.org/doc/qt-5/topics-core.html#threading)
According to the benchmark results:
- const QVector in range-for performs significantly better than non-const QVector since the latter detaches when begin() is called.
- Range-for is about 4x faster than foreach for QVector and for all container sizes, i.e. 5, 5000 and 5'000'000
- Range-for and foreach performs similarly for QHash except for container size of 5000000 where detaching non-const QHash takes 3x to 4x longer than the other 3 configurations.
Attachments
For Gerrit Dashboard: QTBUG-41636 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
115358,5 | Doc: Give advice on foreach vs range-based for | 5.5 | qt/qtbase | Status: MERGED | +2 | 0 |
115446,1 | Doc: Give advice on foreach vs range-based for | 5.5.0 | qt/qtbase | Status: ABANDONED | 0 | 0 |