Java拆箱性能损耗不容忽视

 

public class JavaBoxCost {

    public static void main(String[] args) {

        long start = System.currentTimeMillis();
        for (int i = 0; i < Integer.MAX_VALUE - 10; i++) {
            Integer va = i;
        }
        System.out.println("cost = " + (System.currentTimeMillis() - start));

        start = System.currentTimeMillis();
        for (Integer i = 0; i < Integer.MAX_VALUE - 10; i++) {
            int va = i;
        }
        System.out.println("cost = " + (System.currentTimeMillis() - start));

        /**
         * 最终输出:
         * cost = 5
         * cost = 4781
         */
    }
}

  

Java拆箱性能损耗不容忽视

上一篇:01Java基础语法


下一篇:(16) java Spring Cloud+Spring boot+mybatis企业快速开发架构之SpringCloud-Eureka的REST API及API扩展