title: Does this code fill the CPU cache?
body: <p>I have two ways to program the same functionality.  </p>
  
  <p>Method 1:</p>
  
  <pre><code>doTheWork(int action)
  {
      for(int i = 0 i &lt; 1000000000; ++i)
      {
          doAction(action);
      }
  }
  </code></pre>
  
  <p>Method 2:  </p>
  
  <pre><code>doTheWork(int action)
  {
      switch(action)
      {
      case 1:
          for(int i = 0 i &lt; 1000000000; ++i)
          {
              doAction&lt;1&gt;();
          }
          break;
      case 2:
          for(int i = 0 i &lt; 1000000000; ++i)
          {
              doAction&lt;2&gt;();
          }
          break;
      //-----------------------------------------------
      //... (there are 1000000 cases here)
      //-----------------------------------------------
      case 1000000:
          for(int i = 0 i &lt; 1000000000; ++i)
          {
              doAction&lt;1000000&gt;();
          }
          break;
      }
  }
  </code></pre>
  
  <p>Let's assume that the function <code>doAction(int action)</code> and the function <code>template&lt;int Action&gt; doAction()</code> consist of about 10 lines of code that will get inlined at compile-time. Calling <code>doAction(#)</code> is equiavalent to <code>doAction&lt;#&gt;()</code> in functionality, but the non-templated <code>doAction(int value)</code> is somewhat slower than <code>template&lt;int Value&gt; doAction()</code>, since some nice optimizations can be done in the code when the argument value is known at compile time.  </p>
  
  <p>So my question is, do all the millions of lines of code fill the CPU L1 cache (and more) in the case of the templated function (and thus degrade performance considerably), or does only the lines of <code>doAction&lt;#&gt;()</code> inside the loop currently being run get cached?</p>