Many times I have read that using "for(int i=0; i<size; i++)" to iterate list is bad idea and we must use STL or Java style iterators. I decided to make my own research and calculate processing time for each iterating method. I made 5 trials and calculated average time.

Qt Code:
  1. QList<int> list;
  2. int size = 100000000;
  3. for(int i = 0; i < size; i++)
  4. list.append(1);
  5. int sum = 0;
  6. qint64 begin = QDateTime::currentMSecsSinceEpoch();
  7.  
  8. //Simplest method
  9. for(int i = 0; i < size; i++)
  10. sum += list.at(i);
  11.  
  12. //Java-style iterator
  13. QListIterator<int> it(list);
  14. while(it.hasNext())
  15. sum += it.next();
  16.  
  17. //STL-style iterator
  18. QList<int>::iterator i;
  19. for(i = list.begin(); i != list.end(); ++i)
  20. sum += *i;
  21.  
  22. qint64 time = QDateTime::currentMSecsSinceEpoch() - begin;
  23. qDebug() << "Time: " << time;
To copy to clipboard, switch view to plain text mode 
Results surprised me. Simplest "stupid" method took 85 ms, Java-style iterator 111 ms and STL-iterator 260 ms. It seems that for simple iteration over all list's elements "for(int i=0; i<size; i++)" method will be the fastest.