我无意中遇到了让我感到有些困惑的现象.我正在使用IDLE进行一些快速测试,我有一些非常简单的代码(我为了说明而简化了):
from time import clock # I am presently using windows
def test_speedup():
c = clock()
for i in range(1000):
print i,
print '=>', clock() - c
Run Code Online (Sandbox Code Playgroud)
现在我像这样运行这个代码(几次,具有相同的基本结果):
# without pressing enter
>>> test_speedup()
0 1 2 3 4 . . . 997 998 999 => 12.8300956124 # the time to run code in seconds
# pressing enter ONLY 3 TIMES while the code ran
>>> test_speedup()
0 1 2 3 4 . . . 997 998 999 => 4.8656890089 …Run Code Online (Sandbox Code Playgroud)