Vector vs Array Performance

前端 未结 2 1143
暗喜
暗喜 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: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
    

提交回复
热议问题