Hi all, I've wanted to know if there was any performance difference between using: for(vector<int>::const_iterator it = v.begin(); it != v.end(); ++it)
and for(unsigned int k = 0; k < v.size(); ++k) and it seems there is with gcc 4.1.1, using -O3, the later is almost two times slower. The program is at: http://sat.inesc-id.pt/~pocm/archive/vec.cc Then do: $ g++ -O3 vec.cc -o vec-iter -DITER $ g++ -O3 vec.cc -o vec I got these times: $ time ./vec 5030 elements in array. sum: 27665 real 0m7.123s user 0m7.108s sys 0m0.008s $ time ./vec-iter 5030 elements in array. sum: 27665 real 0m4.699s user 0m4.672s sys 0m0.020s Any comments on these results? They don't seem intuitive to me. Why the difference? Cheers, Paulo Matos _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus