cProfile 只是向您显示在该模块中花费的时间。行号似乎只是表示该模块中处理的第一条语句 - 因为您有一个多行文档字符串,它显示了文档字符串的最后一行。
"""
Test module for cProfile stats
"""
import time
def wait(t):
time.sleep(t)
wait(5)
给出:
$ python -m cProfile test.py
4 function calls in 5.002 seconds
Ordered by: standard name
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 5.001 5.001 test.py:10(wait)
1 0.001 0.001 5.002 5.002 test.py:4(<module>)
1 0.000 0.000 0.000 0.000 {method 'disable' of '_lsprof.Profiler' objects}
1 5.001 5.001 5.001 5.001 {time.sleep}
请注意,第一行显示在函数中花费的时间,wait
而第二行显示在模块中花费的时间。