Faster speed: nested for loops or successive for loops?

倾然丶 夕夏残阳落幕 提交于 2019-12-27 01:58:05

问题


Which is faster, successive for loops or a bunch of nested ones, for example, 3 successive for loops or 3 nested for loops? Will one always be faster than the other?


回答1:


Successive loops will tend to be faster as long as there aren't too many.

In a nested loop, for every increase in an argument n you could have an increase in time that is n squared. With successive loops any increase in n results in a linear change in execution time.



来源:https://stackoverflow.com/questions/37106754/faster-speed-nested-for-loops-or-successive-for-loops

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!