Java for loop vs. while loop. Performance difference?

前端 未结 16 1585
长发绾君心
长发绾君心 2020-11-28 09:35

Assume i have the following code, there are three for loop to do something. Would it run fast if i change the most outer for loop to while loop? thanks~~

<         


        
16条回答
  •  清酒与你
    2020-11-28 10:22

    you cant optimize it by changing it to while.

    you can just increment speed very very very very little by changing the line

    for (int k = 0; k < length - 1; k++) {
    

    by

    for (int k = 0; k < lengthMinusOne; k++) {
    

    where lengthMinusOne is calculated before

    this subtraction is just calculating almost (200x201/2) x (200-1) times and it is very little number for computer :)

提交回复
热议问题