title: Does C/C++ offer any guarantee on minimal execution time?
body: <p>Why do compilers seems to be polite toward loops that do nothing and do not eliminate them?  </p>
  
  <p>Does the C standard require loops to take some time?</p>
  
  <p>Example, the following code:</p>
  
  <pre><code>void foo(void) {
      while(1) {
          for(int k = 0; k &lt; 1000000000; ++k);
          printf("Foo\n");
      }
  }
  </code></pre>
  
  <p>runs slower than this one:</p>
  
  <pre><code>void foo(void) {
      while(1) {
          for(int k = 0; k &lt; 1000; ++k);
          printf("Foo\n");
      }
  }
  </code></pre>
  
  <p>even with <code>-O3</code> optimization level.
  I would expect removing empty loops allowed and thus get the same speed on both codes.  </p>
  
  <p>Is "time spent" a side effect that should be preserved by a compiler?</p>