while(true) 和for(;;) 哪一个的性能比较好呢

public static void main(String[] args) {
      for (;;){
          System.out.println("for");
      }

    }

 public static void main(String[] args) {
      while (true){
          System.out.println("while");
      }

    }

说实话,很差区分,那咱们只能从字节码方面看看,java

while(true) 编译后的字节码性能

 

for(;;) 编译后的字节码code

能够看到,这两个的字节码是一致,全部咱们能够得出结论,这两个死循环的性能是同样的blog

相关文章
相关标签/搜索