title: Boost shared_ptr dereference cost
body: <p>I am trying to compare performance between raw pointers, boost shared_ptr and boost weak_ptr. On the dereferencing part, I expected shared_ptr and raw_ptr to be equal, but results show that shared_ptr is about twice as slow. For the test, I am creating an array with either pointers or shared pointers to ints, and then dereferencing in a loop like this:</p>
  
  <pre><code>int result;
  for(int i = 0; i != 100; ++i)
  {
    for(int i = 0; i != SIZE; ++i)
      result += *array[i];
  }
  </code></pre>
  
  <p>The full code for the test can be found here:
  <a href="https://github.com/coolfluid/coolfluid3/blob/master/test/common/utest-ptr-benchmark.cpp">https://github.com/coolfluid/coolfluid3/blob/master/test/common/utest-ptr-benchmark.cpp</a></p>
  
  <p>Test timings for an optimized build without assertions can be found here:
  <a href="http://coolfluidsrv.vki.ac.be/cdash/testDetails.php?test=145592&amp;build=7777">http://coolfluidsrv.vki.ac.be/cdash/testDetails.php?test=145592&amp;build=7777</a></p>
  
  <p>The values of interest are "DerefShared time" and "DerefRaw time"</p>
  
  <p>I guess the test may be flawed somehow, but I failed to figure out where the difference comes from. Profiling shows the operator* from shared_ptr gets inlined, it just seems to take more time. I double-checked that the boost assertion is off.</p>
  
  <p>I would be very grateful if anyone can explain where the difference might come from.</p>
  
  <p>Additional stand-alone test:
  <a href="https://gist.github.com/1335014">https://gist.github.com/1335014</a></p>