In another thread I started a discussion about Vectors and Arrays, in which I was largely playing devil\'s advocate, to push buttons. However, during the course of this, I
I can guarantee that LLVM does infact misoptimize std::vector (if you are in fact optimising at all), at least as of right now. It does not correctly inline many of the function calls involved. You will get better performance with GCC.
A simpler explanation: you're building with optimisations disabled. You want -O3
, not -o3
.
I don't have clang available to exactly reproduce your tests, but my results are as follows:
//Array run # 1
$ g++ -std=c++11 -O3 test.cpp -o b.out && time ./b.out
real 0m25.323s
user 0m25.162s
sys 0m0.148s
//Vector run #1
$ g++ -std=c++11 -O3 test.cpp -o b.out && time ./b.out
real 0m25.634s
user 0m25.486s
sys 0m0.136s