Vector vs Array Performance

前端 未结 2 1142
暗喜
暗喜 2020-12-31 18:31

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

相关标签:
2条回答
  • 2020-12-31 18:56

    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.

    0 讨论(0)
  • 2020-12-31 18:58

    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
    
    0 讨论(0)
提交回复
热议问题