1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[Python]ループ実行時間の目安

Last updated at Posted at 2021-01-24

条件

以下の二重ループを AtCoder のコードテストで各条件 3 回ずつ実行し、実行時間 (ms) の中央値を記録した。
試行した時間帯は日曜 AM 9 時ごろ。

count = 0
for i in range(n):
  for j in range(m):
	  count += 1
print(count)

実行結果

ネストに関わらず、実行時間はほぼループ回数に依存するとみて良い。

Python 3.8.2

m \ n $10^0$ $10^1$ $10^2$ $10^3$ $10^4$ $10^5$ $10^6$ $10^7$ $10^8$
$10^0$ 107 801 7613
$10^1$ 110 768 7605 TLE
$10^2$ 108 829 7599 TLE
$10^3$ 102 785 7858 TLE
$10^4$ 99 793 7715 TLE
$10^5$ 118 758 7597 TLE
$10^6$ 301 947 6967 TLE
$10^7$ 791 7601 TLE
$10^8$ 7603 TLE

PyPy3 7.3.0

m \ n $10^0$ $10^1$ $10^2$ $10^3$ $10^4$ $10^5$ $10^6$ $10^7$ $10^8$ $10^9$
$10^0$ 277 2135
$10^1$ 280 7384 TLE
$10^2$ 214 1494 TLE
$10^3$ 205 1366 TLE
$10^4$ 189 1273 TLE
$10^5$ 190 1288 TLE
$10^6$ 211 1352 TLE
$10^7$ 216 1426 TLE
$10^8$ 207 1445 TLE
$10^9$ 1386 TLE

太字の外れ値は再現性があった。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?