boost::stable_vector insertion is orders of magnitude slower than std::vector. why? <p>I'm noticing a large performance difference between std::vector and boost::stable_vector. Below is example where I construct and insert 100,000 ints into both a vector and a stable vector.</p> <p>test.cpp:</p> <pre><code>#include &lt;iostream&gt; #include &lt;vector&gt; #include &lt;boost/container/stable_vector.hpp&gt; #include &lt;boost/timer/timer.hpp&gt; int main(int argc, char** argv) { int size = 1e5; boost::timer::cpu_timer timer; timer.start(); std::vector&lt;int&gt; vec(size); timer.stop(); std::cout &lt;&lt; timer.format(); timer.start(); boost::container::stable_vector&lt;int&gt; svec(size); timer.stop(); std::cout &lt;&lt; timer.format(); } </code></pre> <p>compile:</p> <pre><code>g++ -O3 test.cpp -o test -lboost_system-mt -lboost_timer-mt </code></pre> <p>output:</p> <pre><code> 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%) </code></pre> <p>What is the reason for this huge discrepancy? My understanding is that both types should have similar insertion performance.</p> <p>UPDATE: boost version: 1.54</p> <pre><code>dev/stable_vector_test: g++ --version i686-apple-darwin11-llvm-g++-4.2 (GCC) 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2336.11.00) Copyright (C) 2007 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. </code></pre> <p>I added std::list to the code and tried passing -DNDEBUG in addition to -O3.</p> <pre><code>dev/stable_vector_test: make g++ -g test.cpp -o test -lboost_system-mt -lboost_timer-mt dev/stable_vector_test: ./test size: 10000 vector: 0.000047s wall, 0.000000s user + 0.000000s system = 0.000000s CPU (n/a%) list: 0.001168s wall, 0.000000s user + 0.000000s system = 0.000000s CPU (n/a%) stable_vector: 0.963679s wall, 0.960000s user + 0.000000s system = 0.960000s CPU (99.6%) dev/stable_vector_test: make opt g++ -O3 -DNDEBUG test.cpp -o test -lboost_system-mt -lboost_timer-mt dev/stable_vector_test: ./test size: 10000 vector: 0.000038s wall, 0.000000s user + 0.000000s system = 0.000000s CPU (n/a%) list: 0.000659s wall, 0.000000s user + 0.000000s system = 0.000000s CPU (n/a%) stable_vector: 0.000752s wall, 0.000000s user + 0.000000s system = 0.000000s CPU (n/a%) </code></pre> <p>So with -O3 and -DNDEBUG I get comparable performance to std::list</p>