title: Unrolling small loops with Visual Studio 2005
body: <p>How do you tell the compiler to <a href="http://en.wikipedia.org/wiki/Loop_unwinding" rel="nofollow noreferrer">unroll loops</a> based on the number of iterations or some other attribute? Or, <strong>how do you turn on loop unrolling optimization in Visual Studio 2005</strong>?</p>
  
  <p>EDIT: E.g.</p>
  
  <pre><code>//Code Snippet 1
      vector&lt;int&gt; b;
      for(int i=0;i&lt;3;++i) b.push_back(i);
  </code></pre>
  
  <p>As opposed to</p>
  
  <pre><code>//Code Snippet 2
      vector&lt;int&gt; b;
      b.push_back(0);
      b.push_back(1);
      b.push_back(2);
  </code></pre>
  
  <p>push_back() is an example, I could replace this with anything which can take a long time.</p>
  
  <p>But I read somewhere that I can use Code 1 and the compiler can unroll it to Code 2 if the loop satisfies some criteria. So my question is: how do you do that? There's already a discussion on SO as to which one is more efficient but any comments on that is appreciated anyway.</p>