python性能分析器:line_profiler
代码:
import line_profiler
import sys
def test():
for i in range(0, 10):
print( i**2 )
print("End of the function")
prof = line_profiler.LineProfiler(test) #pass in the function to profile
prof.enable() #start profiling
test()
prof.disable() #stop profiling
prof.dump_stats('test.prof')
prof.print_stats(sys.stdout) #print out the results
运行结果:
代码2:
from line_profiler import profile
@profile
def test():
for i in range(0, 10):
print( i**2 )
print("End of the function")
test()
运行结果:
kernprof -l -v B02088_02_17.py
本博客是博主个人学习时的一些记录,不保证是为原创,个别文章加入了转载的源地址,还有个别文章是汇总网上多份资料所成,在这之中也必有疏漏未加标注处,如有侵权请与博主联系。
如果未特殊标注则为原创,遵循 CC 4.0 BY-SA 版权协议。
posted on 2024-07-30 10:36 Angry_Panda 阅读(79) 评论(0) 收藏 举报