Hello, Paulo Matos wrote:
> 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? > LANG=C g++ -v Using built-in specs. Target: i686-pc-linux-gnu Configured with: ../gcc-4.1.1/configure --prefix=/net/opt/gcc-4.1.1 --enable-languages=c,c++ --with-system-zlib --enable-shared --enable-__cxa_atexit --enable-threads=posix Thread model: posix gcc version 4.1.1 > g++ -o vec2 -O3 vec2.cc > g++ -DITER -o veciter2 -O3 vec2.cc > time ./vec2 5030 elements in array. sum: 27665 real 0m5.666s user 0m5.604s sys 0m0.033s > time ./veciter2 5030 elements in array. sum: 27665 real 0m6.588s user 0m6.537s sys 0m0.037s > g++ -o vec2 -O3 -funroll-loops vec2.cc > g++ -DITER -o veciter2 -O3 -funroll-loops vec2.cc > time ./vec2 5030 elements in array. sum: 27665 real 0m3.209s user 0m3.162s sys 0m0.017s > time ./veciter2 5030 elements in array. sum: 27665 real 0m2.846s user 0m2.818s sys 0m0.015s I can't reproduce the extreme difference, but adding -funroll-loops to -O3 changes the picture for me, the iterator version gets the fastest, and both remarkably better. I think the optimization in 4.1.1 is far from finished, and will never be because of 4.2. In older releases the iterator version seems consistenly worse. Bernd Strieder _______________________________________________ help-gplusplus mailing list help-gplusplus@gnu.org http://lists.gnu.org/mailman/listinfo/help-gplusplus