安装,用清华源
pip install line_profiler -i https://pypi.tuna.tsinghua.edu.cn/simple/ --trusted-host pypi.tuna.tsinghua.edu.cn
示例
from line_profiler import LineProfiler
def test(n):
print(n)
n = [i for i in range(20)]
lp = LineProfiler()
lp_wrapper = lp(test)
lp_wrapper(n)
lp.print_stats()
Line # Hits Time Per Hit % Time Line Contents
==============================================================
7 def test(n):
8 1 294.0 294.0 100.0 print(n)