title: Why is the elapsed time in a loop not proportional to the number of iterations
body: <p>I wrote the following code</p>
  
  <pre><code>#define TimeCode(Code) \
  {\
      clock_t t1 = clock();\
      Code \
      clock_t t2 = clock();\
      double elapsed = (t2 - t1) * 1.0 / CLOCKS_PER_SEC;\
      std::cout &lt;&lt; "Elapsed time " &lt;&lt; elapsed &lt;&lt; " sec" &lt;&lt; std::endl; \
  }
  
  void loop(int nz)
  {
      for (int i = 0; i &lt; 5400; i++)
      {
          for (int j = 0; j &lt; 5400; j++)
              for (int k = 0; k &lt; nz; k++)
                  ;
      }
  }
  
  int main(int argc, char* argv[])
  {
  
      TimeCode(loop(17);)
      TimeCode(loop(34);)
      TimeCode(loop(649);)
  
      return 0;
  }
  </code></pre>
  
  <p>I compiled it with <code>g++ -o main main.cpp</code>. The result is</p>
  
  <pre><code>Elapsed time 0.85579 sec
  Elapsed time 3.14095 sec
  Elapsed time 53.7562 sec
  </code></pre>
  
  <p>Then how come the elapsed time is not proportional to the loop size?</p>