実行環境
MacBook Pro
python3.7.5
ループ
while i < N vs for _ in range(N)
i = 0
while i < N: # N=10**6
i += 1
for _ in range(N):
pass
1次元配列
配列の初期化
[None for _ in range(N)] vs [None] * N vs np.empty(N)
tmp = [None for _ in range(N)]
tmp = [None] * N
tmp = np.empty(N)
配列の要素が全て数値で良いなら, Numpyを用いた方が速い
要素の変換
内包表記 vs map関数
tmp = [int(i) for i in range(N)]
tmp = list(map(int,range(N)))
2次元配列(N×N)
[None for_in range(N)]for_in range(N)] vs [[None]*N for_in range(N)] vs np.empty((N,N))
tmp = [None for _ in range(N]for _ in range(N)]
tmp = [[None] * N for _ in range(N)]
tmp = np.empty((N,N))