所以我可以使用 time.clock() 来测量函数调用的运行时间:
>>> def f() :
a = time.clock()
range(pow(10,8))
b = time.clock()
print a,b
>>> f()
0.143698 8.345905
但是现在如果从交互式 shell 中重复调用 time.clock():
>>> 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对应什么呢?
我确实看了文档,但我还是不明白:
Help on built-in function clock in module time:
clock(...) clock() -> floating point number
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.
请您参考如下方法:
什么系统?
“此方法以 float 形式返回当前处理器时间,在 Unix 中以秒表示,在 Windows 中它以 float 形式返回自第一次调用此函数以来经过的挂钟秒数。”
