【发布时间】:2011-06-12 16:48:07
【问题描述】:
考虑以下示例:
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 秒,而不是在睡眠的情况下。
谁能解释我为什么会得到这样的结果?
谢谢!
【问题讨论】: