Python では多重のループを避ける的な風潮があるが気になったので適当に比較。
計測環境は
ループ回数が 600 * 600 の時の実行時間は
Time_01 : 0.0446324348449707Sec
Time_12 : 0.10829639434814453Sec
ループ回数が 10000 * 10000 の時の実行時間は
Time_01 : 15.341634273529053Sec
Time_12 : 32.571099281311035Sec
多重ループを避けた方は divmod 関数がいるからか逆に重くなった。
### Loop Count s = 600 time_0 = time.time() ### Loop Loop ### 0.049633026123046875 Sec count = 0 for i in range(s): for j in range(s): count += 1 tmp = [i, j] print(count) time_1 = time.time() ### Loop ### 0.11133432388305664 Sec ss = s * s count = 0 for i in range(ss): count += 1 u, v = divmod(i, ss) tmp = [u, v] print(count) time_2 = time.time() print("Time_01 : {}Sec".format(time_1 - time_0)) print("Time_12 : {}Sec".format(time_2 - time_1))