title: Java Condition Operators Speed vs Versions of Hotspot VM
body: <p>Please consider the following java source:</p>
  
  <p><code></p>
  
  <pre><code>package com.stackoverflow;
  
   public class CondSpeed {
   private static final long COUNT = 1000000000;
   private static final long OUTER_COUNT = 15;
  
   private static long notEqOperator = 0L;
    private static long notOperator = 0L;
  private static long equalsFalse = 0L;
  
  public CondSpeed() {
   super();
  }
  
  public static void main(String[] args) {
  
   for(int outCount = 0;outCount &lt; OUTER_COUNT;outCount++){
    notEqOperator += testNotEaualsOperator();
    equalsFalse += testEqualFalse();
    notOperator += testNotOperator();
   }
  
   long avrForNotEqOperator = (notEqOperator / OUTER_COUNT);
   long avrForEqualsFalse = (equalsFalse / OUTER_COUNT);
   long avrForNotOperator = (notOperator / OUTER_COUNT);
  
   System.out.println("Avr for Not Equals Operator: "+avrForNotEqOperator);
   System.out.println("Avr for Equals \"false\" Operator: "+avrForEqualsFalse);
   System.out.println("Avr for Not Operator: "+avrForNotOperator);
  
  }
  
  private static long testEqualFalse(){
   long now = System.currentTimeMillis();
  
   for(long i = 0;i &lt; COUNT;i++){
    boolean truFalse = returnTrueOrFalse();
  
    if(truFalse == false){
     //do nothing...
    }
   }
  
   return (System.currentTimeMillis() - now);
  }
  
  
     private static long testNotOperator(){
   long now = System.currentTimeMillis();
  
   for(long i = 0;i &lt; COUNT;i++){
    boolean truFalse = returnTrueOrFalse();
  
    if(!truFalse){
  //do nothing...
    }
   }
  
   return (System.currentTimeMillis() - now);
  }
  
  private static long testNotEaualsOperator(){
   long now = System.currentTimeMillis();
  
   for(long i = 0;i &lt; COUNT;i++){
    boolean truFalse = returnTrueOrFalse();
  
    if(truFalse != true){
     //do nothing...
    }
   }
  
   return (System.currentTimeMillis() - now);
  }
  
  private static boolean isFalse;
  private static boolean returnTrueOrFalse(){
   if(isFalse){
    isFalse = false;
   }
   else{
    isFalse = true;
   }
   return isFalse;
  }
  
  }
  </code></pre>
  
  <p></code></p>
  
  <p>As you can see it is a test against 3 versions of <strong><em>if(false)</em></strong> conditions.</p>
  
  <ul>
  <li>I am interested in why the results are firstly different in the various condition statements. ((I know that its obviously the way the compiler interpretes the .java into bytecode.)) Is there more to it than this?
  <li>Secondly. Look at the differences in different Hotspot VMs. See bottom. Is this because of updates/improvements the the VM over versions? Or is there more to it?
  <li>Is this the best way to test something like this?
  </ul>
  
  <p><strong>---Results Mac OS X---</strong></p>
  
  <p><strong><em>JavaVM HotSpot 1.6.0</em></strong></p>
  
  <p>Avr for Not Equals Operator: <em>1937</em><br>
  Avr for Equals "false" Operator: <em>1937</em><br>
  Avr for Not Operator: <em>1941</em>  </p>
  
  <p><strong><em>JavaVM HotSpot 1.5.0</em></strong></p>
  
  <p>Avr for Not Equals Operator: <em>5023</em><br>
  Avr for Equals "false" Operator: <em>5035</em><br>
  Avr for Not Operator: <em>5067</em>  </p>
  
  <p><strong><em>JavaVM HotSpot 1.4.2</em></strong></p>
  
  <p>Avr for Not Equals Operator: <em>3993</em><br>
  Avr for Equals "false" Operator: <em>4015</em><br>
  Avr for Not Operator: <em>4009</em>  </p>
  
  <p><strong><em>JavaVM HotSpot 1.4.0</em></strong></p>
  
  <p>Avr for Not Equals Operator: <em>3961</em><br>
  Avr for Equals "false" Operator: <em>3960</em><br>
  Avr for Not Operator: <em>3961</em>  </p>
  
  <p>Thanks. </p>