python性能分析工具

使用第三方工具line_profiler

python3.6

1、安装
直接使用pip install line_profiler报错:
ERROR: Failed building wheel for line-profiler
Failed to build line-profiler
ERROR: Could not build wheels for line-profiler which use PEP 517 and cannot be installed directly
使用方法
pip3 install Cpython
pip3 install Cython git+https://github.com/rkern/line_profiler.git
但是安装Cpython没报错,运行第二行命令却报错:ModuleNotFoundError: No module named ‘cython’
解决办法,pip3 install --upgrade cython

最终安装命令顺序如下:
1)、pip3 install Cpython
2)、pip3 install --upgrade cython
3)、pip3 install Cython git+https://github.com/rkern/line_profiler.git

2、使用方法
prof = line_profiler.LineProfiler(函数名)
prof.enable()
函数调用
prof.disable()
prof.print_stats(sys.stdout)

3、输出
在这里插入图片描述
Timer unit: 3.41307e-07 s :表示单位时间
Total time: 0.792417 s :表示运行总时间
Line # :表示在代码行数
Hits :表示该行代码运行次数
Time :表示运行该行运行总时间
Per Hit :表示该行每次运行需要时间
% Time :表示该行耗时占总耗时百分比
Line Contents :表示代码内容

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值