title: what's faster: recreate or clear()?
body: <p>I have a question about the performance of the std::vector&lt;> in C++. Is it faster to reuse the same vector by calling its clear() method or it it faster to recreate the vector?</p>
  
  <p>The following example is no real life code, it's only for making clear what the question is:</p>
  
  <pre><code>//Example ONE: is this faster
  std::vector&lt;int&gt; foo;
  for(int i = 0; i &lt; 100; ++i)
  {
      foo.clear();
      for(int j = 0; j &lt; 100; ++j)
      {
          foo.push_back(i+j);
      }
  }
  
  //Example TWO: or is that faster?
  for(int i = 0; i &lt; 100; ++i)
  {
      std::vector&lt;int&gt; foo;
      for(int j = 0; j &lt; 100; ++j)
      {
          foo.push_back(i+j);
      }
  }
  </code></pre>