【python性能测试】line_profiler每行代码的耗时统计/空间占用/整体性能分析

耗时统计之line_profiler

1、安装line_profiler

pip install line_profiler -i https://pypi.tuna.tsinghua.edu.cn/simple
# 参考 https://github.com/pyutils/line_profiler

2、添加@profile
想统计那个方法的耗时,就在方法头添加装饰器@profile,如下所示:
ex:test.py

from line_profiler import LineProfiler

@profile
def test(self):
    for i in range(1,100):
        print(i)

3、统计耗时
执行如下命令:
kernprof -l -v test.py
输出示例:
在这里插入图片描述
ref:https://blog.csdn.net/guofangxiandaihua/article/details/77825524

内存占用统计之memory_profiler

ref: https://www.jianshu.com/p/a06a715b5a52

整体性能统计之psrecord

1、安装
pip install psrecord -i https://pypi.tuna.tsinghua.edu.cn/simple
2、统计
命令格式: command pid --log log_file --duration 间隔时间
重定向到文件
psrecord 10776 --log activity.txt --duration 10
重定向到图片
psrecord 10776 --plot plot.png --duration 10

ref:
https://github.com/astrofrog/psrecord

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值