title: is std::packaged_task really expensive?
body: <p>I am surprised at the results of the following code using gcc 4.7.2 on Opensuse Linux:</p>
  
  <pre><code>#include &lt;cmath&gt;
  #include &lt;chrono&gt;
  #include &lt;cstdlib&gt;
  #include &lt;vector&gt;
  #include &lt;chrono&gt;
  #include &lt;iostream&gt;
  #include &lt;future&gt;
  
  int main(void)
  {
    const long N = 10*1000*1000;
    std::vector&lt;double&gt; array(N);
    for (auto&amp; i : array)
      i = rand()/333.;
  
    std::chrono::time_point&lt;std::chrono::system_clock&gt; start, end;
    start = std::chrono::system_clock::now();
    for (auto&amp; i : array)
      pow(i,i);
    end = std::chrono::system_clock::now();
    std::chrono::duration&lt;double&gt; elapsed_seconds = end-start;
    std::cout &lt;&lt; "elapsed time: " &lt;&lt; elapsed_seconds.count() &lt;&lt; "s\n";
  
    start = std::chrono::system_clock::now();
    for (auto&amp; i : array)
      std::packaged_task&lt;double(double,double)&gt; myTask(pow);
    elapsed_seconds = std::chrono::system_clock::now()-start;
    std::cout &lt;&lt; "elapsed time: " &lt;&lt; elapsed_seconds.count() &lt;&lt; "s\n";
  
    start = std::chrono::system_clock::now();
    for (auto&amp; i : array)
      std::packaged_task&lt;double()&gt; myTask(std::bind(pow,i,i));
    elapsed_seconds = std::chrono::system_clock::now()-start;
    std::cout &lt;&lt; "elapsed time: " &lt;&lt; elapsed_seconds.count() &lt;&lt; "s\n";
  
    return 0;
  }
  </code></pre>
  
  <p>The results look like this (and are fairly consistent amongst runs):</p>
  
  <pre><code>elapsed time: 0.694315s
  elapsed time: 6.49907s
  elapsed time: 8.42619s
  </code></pre>
  
  <p>If I interpret the results correctly, just <em>creating</em> a <code>std::packaged_task</code> (not even executing it or storing its arguments yet) is already ten times more expensive than <code>executing</code> <code>pow</code>. Is that a valid conclusion?</p>
  
  <p>Why is this so? </p>
  
  <p>Is this by accident gcc specific?</p>