环境
3.9
我通过点对点安装了线路轮廓仪。
sudo pip3 install line-profiler
详细信息
add_function和runcall工作。没关系。
import line_profiler
def hoge():
n = 0
for i in range(100):
n += i
print(n)
pr = line_profiler.LineProfiler()
pr.add_function(hoge)
pr.runcall(hoge)
pr.print_stats()% python3.9 profile1.py
4950
Timer unit: 1e-06 s
Total time: 6.1e-05 s
File: /home/miwa/work/lang/python/profile1.py
Function: hoge at line 4
Line # Hits Time Per Hit % Time Line Contents
==============================================================
4 def hoge():
5 1 1.0 1.0 1.6 n = 0
6 101 23.0 0.2 37.7 for i in range(100):
7 100 25.0 0.2 41.0 n += i
8 1 12.0 12.0 19.7 print(n)但是enable和disable不起作用。
只输出“计时器单元”。
它的使用是否不正确?
import line_profiler
def hoge():
n = 0
for i in range(100):
n += i
print(n)
pr = line_profiler.LineProfiler()
pr.enable()
hoge()
pr.disable()
pr.print_stats()% python3.9 profile0.py
4950
Timer unit: 1e-06 s发布于 2022-10-03 12:03:56
line-profiler似乎不能和cProfile (启用-运行-禁用语法)一样使用。看看this answer有两种不同的方式。
https://stackoverflow.com/questions/66470938
复制相似问题