title: Two operations in one loop vs two loops performing the same operations one per loop
body: <p>This question is identical to this
  <a href="https://stackoverflow.com/questions/3322136/two-loop-bodies-or-one-result-identical">Two loop bodies or one (result identical)</a>
  but in my case, I use Java. </p>
  
  <p>I have two loops that runs a billion times.</p>
  
  <pre><code>int a = 188, b = 144, aMax = 0, bMax = 0;
  
  for (int i = 0; i &lt; 1000000000; i++) {
    int t = a ^ i;
    if (t &gt; aMax) 
      aMax = t;     
  }  
  
  for (int i = 0; i &lt; 1000000000; i++) {
    int t = b ^ i;
    if (t &gt; bMax) 
      bMax = t;     
  }  
  </code></pre>
  
  <p>The time it takes to run these two loops in my machine is appr 4 secs. When I fuse these two loops into a single loop and perform all the operations in that single loop, then it runs in 2 secs.  As you can see trivial operations makes up the loop contents, thus requiring constant time.</p>
  
  <p>My question is where am I getting this performance improvement? </p>
  
  <p>I am guessing that the only possible place where performance gets affected in the two separate loops is that it increments i and checks if i &lt; 1000000000 2 billion times vs only 1 billion times if I fuse the loops together. Is anything else going on in there?</p>
  
  <p>Thanks!   </p>