仅仅是大小写之差,性能居然相差十倍
什么?一个字母的大小写就能让程序的性能相差十倍,不是吧啊sir。
不相信的话来看看下面这段代码
/**
* @author :Negen
* @Date :Created in 14:05 2020/5/22
* @Description:
* @Modified By:
* @Version: 1.0
*/
public class TestAutoBoxing {
public static void main(String[] args) {
LongSum();
longSum();
}
public static void LongSum() {
long start = System.currentTimeMillis();
Long sum = 0L;
for (long i = 0; i <= Integer.MAX_VALUE; i++)
sum += i;
long end = System.currentTimeMillis();
long cost = end - start;
System.out.println("cost time:" + cost);
System.out.println("Long result:" + sum);
}
public static void longSum() {
long start = System.currentTimeMillis();
long sum = 0L;
for (long i = 0; i <= Integer.MAX_VALUE; i++)
sum += i;
long end = System.currentTimeMillis();
long cost = end - start;
System.out.println("cost time:" + cost);
System.out.println("long result:" + sum);
}
}
有没有看出差别在哪儿啊,没有的话手动运行下,再看看两个方法的区别在哪儿!!!