Java拆箱性能损耗不容忽视

时间:2021-09-17 14:47:42   收藏:0   阅读:43

 

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
         */
    }
}

  

原文:https://www.cnblogs.com/leodaxin/p/15302450.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!