package com.hknaruto;
import java.util.Random;
/**
* Created by yeqiang on 4/24/18.
*/
public class IntegerPerformanceTest {
public static void main(String[] args) {
long start, end;
int rand = new Random().nextInt();
start = System.nanoTime();
int c = 0;
for (Integer i = 0; i < 100000000; i++) {
c += rand + i;
}
end = System.nanoTime();
System.out.println(c);
System.out.println(end - start);
start = System.nanoTime();
c = 0;
for (int i = 0; i < 100000000; i++) {
c += rand + i;
}
end = System.nanoTime();
System.out.println(c);
System.out.println(end - start);
}
}
输出
-1508346240
396963018
-1508346240
34686095
最后
以上就是直率百褶裙最近收集整理的关于Java基本类型int与类类型Integer性能差别的全部内容,更多相关Java基本类型int与类类型Integer性能差别内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复