尽量少用Autoboxing

平时工作中不太注意autoboxing的问题, 顺手就用了装箱类型。后来发现执行效率差距还是蛮大的。 

 public class BoxingTesting {
    public static void main(String args[]) {
    	long start = System.nanoTime();
    	Long sum = 0L;
    	for(int i = 0; i < Integer.MAX_VALUE; i++){
    		sum += i;
    	}
    	long end = System.nanoTime();
    	System.out.println(end - start);
    	
    	long start1 = System.nanoTime();
    	long sum1 = 0L;
    	for(int i = 0; i < Integer.MAX_VALUE; i++){
    		sum1 += i;
    	}
    	
    	long end1 = System.nanoTime();
    	System.out.println(end1 - start1);
    	
    	System.out.println((end - start)/(end1 - start1));
    	
    }
}

你可能感兴趣的:(java,AutoBoxing)