Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-41636

Improve container documentation for foreach and range-based for loop

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Done
    • P3: Somewhat important
    • None
    • None
    • Documentation
    • 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

        1. rangefor_test.tar.gz
          1 kB
        2. results_clang3.4.txt
          5 kB
        3. results_gcc4.6.txt
          5 kB
        For Gerrit Dashboard: QTBUG-41636
        # Subject Branch Project Status CR V

        Activity

          People

            docteam Qt Documentation Team
            ckakman Kayra Akman
            Votes:
            2 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes