小编kma*_*lle的帖子

boost :: stable_vector插入比std :: vector慢几个数量级.为什么?

我注意到std :: vector和boost :: stable_vector之间存在很大的性能差异.下面是我构建并在向量和稳定向量中插入100,000个int的示例.

TEST.CPP:

#include <iostream>
#include <vector>
#include <boost/container/stable_vector.hpp>
#include <boost/timer/timer.hpp>

int main(int argc, char** argv) {
    int size = 1e5;
    boost::timer::cpu_timer timer;

    timer.start();
    std::vector<int> vec(size);
    timer.stop();
    std::cout << timer.format();

    timer.start();
    boost::container::stable_vector<int> svec(size);
    timer.stop();
    std::cout << timer.format();
}
Run Code Online (Sandbox Code Playgroud)

编译:

g++ -O3 test.cpp -o test -lboost_system-mt -lboost_timer-mt
Run Code Online (Sandbox Code Playgroud)

输出:

 0.000209s wall, 0.000000s user + 0.000000s system = 0.000000s CPU (n/a%)
 5.697013s wall, 5.690000s user + 0.000000s system = 5.690000s CPU (99.9%)
Run Code Online (Sandbox Code Playgroud)

造成这种巨大差异的原因是什么?我的理解是两种类型都应具有相似的插入性能.

更新:提升版本:1.54

dev/stable_vector_test: g++ --version
i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 …
Run Code Online (Sandbox Code Playgroud)

c++ boost

5
推荐指数
1
解决办法
1667
查看次数

标签 统计

boost ×1

c++ ×1