title: Intel TBB it's 2 time slower than std - tbb vs std
body: <p>I have done a little comparison between 2 programs that are filling a given vector with pseudo-random integers from a mersenne twister, the point is that the TBB version it's terribly slow, the std version is performing the task in about 0.6s when TBB needs at least 1.1s .</p>
  
  <p>I have also noticed that TBB doesn't really offers optimized algorithms to work with containers but it only offers generic constructs ( parallel_for, parallel_for_each and similar ) to work with generic tasks where std offers <code>std::generate</code> that is a much better and cleaner solution in this case.</p>
  
  <p>You can download my small test with the 2 small source files + a Makefile for gcc here <a href="http://www.sendspace.com/file/ew73h8" rel="nofollow">http://www.sendspace.com/file/ew73h8</a></p>
  
  <p>I'm doing something wrong here ? the more I increase the size of this vector the slower TBB gets, I'm under Ubuntu 13.04 64 bit with an Intel Q6600.</p>
  
  <p>The TBB version could be better in some way ?</p>
  
  <p>EDIT : full sources for the 2 files</p>
  
  <hr>
  
  <p><strong>config.hpp</strong></p>
  
  <pre><code>#define N 10000000
  </code></pre>
  
  <p><strong>std.cpp</strong></p>
  
  <pre><code>#include &lt;random&gt;
  #include &lt;iostream&gt;
  #include &lt;vector&gt;
  #include &lt;algorithm&gt;
  
  #include "config.hpp"
  
  int main() {
  
      std::vector&lt;u_int32_t&gt; v(N);
  
      std::mt19937 mt;
      std::uniform_int_distribution&lt;u_int32_t&gt; dist(0,499);
  
      std::generate(v.begin(),v.end(),[&amp;]{return dist(mt);});
  
      return(0);
  }
  </code></pre>
  
  <p><strong>tbb.cpp</strong></p>
  
  <pre><code>#include &lt;tbb/concurrent_vector.h&gt;
  #include &lt;tbb/parallel_for_each.h&gt;
  
  #include &lt;random&gt;
  #include &lt;iostream&gt;
  
  #include "config.hpp"
  
  int main()
  {
    tbb::concurrent_vector&lt;u_int32_t&gt; v(N);
    std::mt19937 mt;
    std::uniform_int_distribution&lt;u_int32_t&gt; dist(0, 499);
    tbb::parallel_for_each(v.begin(),v.end(),[&amp;](u_int32_t&amp; e){e = dist(mt); });
  
    return(0);
  }
  </code></pre>