问题
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