如何找出每行python代码的执行时间.
line_profiler适用于ipython,但不适用于jupyter笔记本电脑.我try 将@profile添加到我的函数中,它给出了一个错误,即没有定义名称"profile".
def prof_function():
x=10*20
y=10+x
return (y)
如何找出每行python代码的执行时间.
line_profiler适用于ipython,但不适用于jupyter笔记本电脑.我try 将@profile添加到我的函数中,它给出了一个错误,即没有定义名称"profile".
def prof_function():
x=10*20
y=10+x
return (y)
你可以在jupyter笔记本中使用line_profiler
.
pip install line_profiler
%load_ext line_profiler
prof_function
. %lprun -f prof_function prof_function()
将提供以下输出:
Timer unit: 1e-06 s
Total time: 3e-06 s
File: <ipython-input-22-41854af628da>
Function: prof_function at line 1
Line # Hits Time Per Hit % Time Line Contents
==============================================================
1 def prof_function():
2 1 1.0 1.0 33.3 x=10*20
3 1 1.0 1.0 33.3 y=10+x
4 1 1.0 1.0 33.3 return (y)