title: Is a big loop within a small loop always faster than a small loop within a big one?
body: <p>I just read <a href="https://stackoverflow.com/questions/23107563/why-is-a-big-loop-within-a-small-loop-faster-than-a-small-loop-within-a-big-one">this post</a>, and wonder if we can draw the conclusion that a big loop within a small loop must always run faster than a small loop within a big one, no matter what the code does inside the nested loop? Take an example.</p>
  <pre><code>int m, n; 
  m = 1000000;
  n = 10;
  </code></pre>
  <p>Snippet A</p>
  <pre><code>for (int i = 0; i &lt; n; i++)         
      for (int j=0; j &lt; m; j++)               
         {       
             DoSomething();        
         }
  
     
  </code></pre>
  <p>Snippet B</p>
  <pre><code>for (int j = 0; j &lt; m; j++)               
      for (int i=0; i &lt; n; i++)           
         {       
            DoSomething();          
         }
  
     
  </code></pre>
  <p>Can we say that, no matter what DoSomething() actually does, snippet A always runs faster thant snippet B?</p>
  <hr />
  <p>As pointed out by @stackmate, I want to expand this question into two</p>
  <ol>
  <li><p>When the code inside nested loop is DoSomething() which means
  DoSomething() has nothing to do with variable i and j. What is
  the performance difference?</p>
  </li>
  <li><p>When the code inside nested loop is DoSomething(i, j) which means
  DoSomething(i, j) has relateship with variable i and j. What is the performance difference?</p>
  </li>
  </ol>