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

QVector iteration much slower in 5.4.1 than in 4.8.4

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 5.4.1
    • None
    • Visual Studio 2013, Windows 7

    Description

      While trying to upgrade our software from VS 2010 to VS 2013, I also upgraded Qt from 4.8.4 to 5.4.1. I noticed that parts of the application ran considerably slower. I found the cause of the problem in QVector, which is much slower in 5.4.1 than in 4.8.4 (I haven't tested any other 5.* releases).

      Here are my test results:

      Loop over 500Mio int Qt 4.8.4, VS 2010 Qt 5.4.1, VS 2013 Factor
      QVector::iterators 193ms 729ms 3.7
      QVector::operator[] 417ms 970ms 2.3
      std::vector::iterators 194ms 132ms 0.68
      std::vector::operator[] 156ms 130ms 0.83

      Looking at the code, every access to operator[] or constBegin() has much more overhead than it used to have in 4.8.4. Also compared to STL, performance is quite bad in this case. Is this bad QVector performance a known issue and planned to be resolved? Otherwise it seems we'll have to switch from QVector to std::vector.

      Test Code:

          const int _size = 500 * 1000 * 1000;
          int _sum = 0;
          QVector<int> _vector(_size, 0);
          std::vector<int> _vector2(_size, 0);
          myTimer _timer;
          for (int i = 0; i < _size; i++)
          {
            _sum += _vector[i];
          }
          _timer.measure("QVector::operator[]");
          for (auto _iter = _vector.constBegin(); _iter != _vector.constEnd(); _iter++)
          {
            _sum += *_iter;
          }
          _timer.measure("QVector::iterators");
      
          for (int ii = 0; ii < _size; ii++)
          {
            _sum += _vector2[ii];
          }
          _timer.measure("std::vector::operator[]");
          for (auto _iter2 = _vector2.cbegin(); _iter2 != _vector2.cend(); _iter2++)
          {
            _sum += *_iter2;
          }
          _timer.measure("std::vector::iterators");
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            thiago Thiago Macieira
            Urs Urs Doenni
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes