的行爲,因此我可以使用time.clock()
來衡量一個函數調用的運行時間:困惑time.clock的Python中
>>> def f() :
a = time.clock()
range(pow(10,8))
b = time.clock()
print a,b
>>> f()
0.143698 8.345905
但是現在如果只是調用time.clock()
重複地從交互式shell:
>>> time.clock()
0.075492
>>> time.clock()
0.075931
>>> time.clock()
0.076354
>>> time.clock()
0.076754
>>> time.clock()
0.077132
...
這些數字的含義是什麼?
現在,如果我這樣做:
>>> def g() :
a = time.clock()
time.sleep(10)
b = time.clock()
print a,b
>>> g()
8.361528 8.361625
好吧,我想這sleep
不處理時間計算在內,因此這兩個數字非常接近。但是8.361528對應什麼?在模塊時間
幫助的內置功能時鐘:
我看過的文檔,但我還是不明白
時鐘(...) 時鐘() - >浮點數
Return the CPU time or real time since the start of the process or since the first call to clock(). This has as much precision as the system records.
參見例如http://stackoverflow.com/a/25317322/3001761 – jonrsharpe 2014-08-27 12:50:28
@jonrsharpe:我一定很愚蠢,但我還是不明白數字0.077和8.36的意思。 – 2014-08-27 13:16:15
@usualme:不解釋絕對值,解釋*相對差異*。這是你唯一關心的。 – 2014-08-27 13:27:38