Java for loop vs. while loop. Performance difference?

前端 未结 16 1586
长发绾君心
长发绾君心 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:39

    This kind of micro-optimization is pointless.

    • A while-loop won’t be faster.
    • The loop structure is not your bottleneck.
    • Optimize your algorithm first.
    • Better yet, don’t optimize first. Only optimize after you have found out that you really have a bottleneck in your algorithm that is not I/O-dependant.

提交回复
热议问题