Hello d_stranz,

I don't quite understand the use of 'const'.
However I ran test 'f7' along with those already posted.

Regards
Qt Code:
  1. auto start_time7 = std::chrono::high_resolution_clock::now();
  2. for (int t = 0; t < 100; t++)
  3. {
  4. for (int s = 0; s < 1000; s++)
  5. f7 (1000, v);
  6. }
  7. auto end_time7 = std::chrono::high_resolution_clock::now();
  8. auto time7 = end_time7 - start_time7;
  9. d = std::chrono::duration_cast<std::chrono::microseconds>(time7).count();
  10. std::cout << "f7 took " << (d / 100) << " microseconds.\n";
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. #pragma GCC push_options
  2. #pragma GCC optimize ("O0")
  3. void MainWindow::f7(int n, std::vector<int> v) {
  4. int k;
  5. for (int i = 0; i < n; i++)
  6. {
  7. for (std::vector<int>::iterator it = v.begin() ; it != v.end(); ++it)
  8. {
  9. k = *it;
  10. //qDebug() << *it << k;
  11. }
  12. }
  13. }
  14. #pragma GCC pop_options
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. vector
  2. f0 took 168825 microseconds.
  3. f6 took 167124 microseconds.
  4. f1 took 136416 microseconds.
  5. f2 took 155180 microseconds reverse.
  6. f3 took 89297.5 microseconds.
  7. f7 took 128919 microseconds. //***
  8.  
  9. array
  10. f4 took 71238 microseconds.
  11. f5 took 66366.4 microseconds reverse.
To copy to clipboard, switch view to plain text mode