Why is “while (i++ < n) {}” significantly slower than “while (++i < n) {}”

后端 未结 5 2132
长发绾君心
长发绾君心 2020-12-04 14:16

Apparently on my Windows 8 laptop with HotSpot JDK 1.7.0_45 (with all compiler/VM options set to default), the below loop

final int n = Integer.MAX_VALUE;
in         


        
5条回答
  •  温柔的废话
    2020-12-04 14:34

    probably this test is not enough to take conclusions but I would say if this is the case, the JVM can optimize this expression by changing i++ to ++i since the stored value of i++ (pre value) is never used in this loop.

提交回复
热议问题