Created
June 1, 2016 03:33
-
-
Save adeekshith/623c9c973b5c8872e9c3532dfb70fb11 to your computer and use it in GitHub Desktop.
Testing performance between `Integer == int` vs `int == Integer`
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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