Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Coincidentally I made a speed test recently (filling 10 * 1024 * 1024 ints with rand() ).<br> These are 3 runs, time in nano-seconds </p> <pre><code>vect[i] time : 373611869 vec.at(i) time : 473297793 *it = time : 446818590 arr[i] time : 390357294 *ptr time : 356895778 </code></pre> <p>UPDATE : added stl-algorithm std::generate, which seems to run the fastest, because of special iterator-optimizing (VC++2008). time in micro-seconds.</p> <pre><code>vect[i] time : 393951 vec.at(i) time : 551387 *it = time : 596080 generate = time : 346591 arr[i] time : 375432 *ptr time : 334612 </code></pre> <p>Conclusion : Use standard-algorithms, they might be faster than a explicit loop ! (and also good practice) </p> <p>Update : the above times were in a I/O-bound situation, I did the same tests with a CPU-bound (iterate over a relatively short vector, which should fit in cache repeatedly, multiply each element by 2 and write back to vector)</p> <pre><code>//Visual Studio 2008 Express Edition vect[i] time : 1356811 vec.at(i) time : 7760148 *it = time : 4913112 for_each = time : 455713 arr[i] time : 446280 *ptr time : 429595 //GCC vect[i] time : 431039 vec.at(i) time : 2421283 *it = time : 381400 for_each = time : 380972 arr[i] time : 363563 *ptr time : 365971 </code></pre> <p>Interestingly iterators and operator[] is considerably slower in VC++ compared to for_each (which seems to degrade the iterators to pointers through some template-magic for performance).<br> In GCC access times are only worse for at(), which is normal, because it's the only range-checked function of the tests. </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload