title: Why does a 4 billion-iteration Java loop take only 2 ms?
body: <p>I'm running the following Java code on a laptop with 2.7 GHz Intel Core i7. I intended to let it measure how long it takes to finish a loop with 2^32 iterations, which I expected to be roughly 1.48 seconds (4/2.7 = 1.48).</p>
  
  <p>But actually it only takes 2 milliseconds, instead of 1.48&nbsp;s. I'm wondering if this is a result of any JVM optimization underneath?</p>
  
  <pre><code>public static void main(String[] args)
  {
      long start = System.nanoTime();
  
      for (int i = Integer.MIN_VALUE; i &lt; Integer.MAX_VALUE; i++){
      }
      long finish = System.nanoTime();
      long d = (finish - start) / 1000000;
  
      System.out.println("Used " + d);
  }
  </code></pre>