3
考虑下面的例子:谅解CPU秒
import hotshot
import hotshot.stats
import time
def test_sleep():
time.sleep(1)
def main():
prof = hotshot.Profile("lol.prof")
prof.runcall(test_sleep)
prof.close()
stats = hotshot.stats.load("lol.prof")
stats.sort_stats("time", "calls")
stats.print_stats(20)
if __name__ == "__main__":
main()
我得到这样的输出:
debian:# python lol.py
1 function calls in 1.000 CPU seconds
Ordered by: internal time, call count
ncalls tottime percall cumtime percall filename:lineno(function)
1 1.000 1.000 1.000 1.000 lol.py:6(test_sleep)
0 0.000 0.000 profile:0(profiler)
我预计将有0秒CPU时间和1秒挂钟时间。
我期望在繁忙的循环的情况下,1个CPU第二,不睡眠的情况下。
有人可以解释为什么我会得到这样的结果吗?
谢谢!
是否记录在某处?我用cProfile得到了同样的结果。 “时间python.lol”工作正常。 – lstipakov 2011-01-20 20:57:56