Skip to content

Instantly share code, notes, and snippets.

@adeekshith
Created June 1, 2016 03:33
Show Gist options
  • Save adeekshith/623c9c973b5c8872e9c3532dfb70fb11 to your computer and use it in GitHub Desktop.
Save adeekshith/623c9c973b5c8872e9c3532dfb70fb11 to your computer and use it in GitHub Desktop.
Testing performance between `Integer == int` vs `int == Integer`
import java.util.Arrays;
import java.util.List;
import java.util.ListIterator;
public class IntegerTest {
public static void main(String[] args) {
long startTime;
long duration;
long endTime;
Integer thisInt = new Integer(10);
startTime = System.nanoTime();
for(int iter1=0; iter1<1000; iter1++){
if(thisInt.equals(iter1)){};
}
endTime = System.nanoTime();
duration = (endTime - startTime); //divide by 1000000 to get milliseconds.
System.out.println(duration);
startTime = System.nanoTime();
for(int iter1=0; iter1<1000; iter1++){
if(thisInt == iter1){};
}
endTime = System.nanoTime();
duration = (endTime - startTime); //divide by 1000000 to get milliseconds.
System.out.println(duration);
startTime = System.nanoTime();
for(int iter1=0; iter1<1000; iter1++){
if(iter1 == thisInt){};
}
endTime = System.nanoTime();
duration = (endTime - startTime); //divide by 1000000 to get milliseconds.
System.out.println(duration);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment