User-Profile-Image
hankin
  • 5
  • centos7
  • docker
  • mysql
  • PostgreSQL
  • git/gitlab
  • ELK
  • python
    • python-Tornado
    • python-django
  • redis
  • nginx
  • kvm
  • proxmox
  • mongo
  • kubernetes
  • prometheus
  • GlusterFs
  • nfs
  • freeswitch
  • httpd
  • shell脚本
  • linux
  • fastdfs
  • nextcloud
  • openssl
  • openvpn
  • rabbitmq
  • sqlite
  • svn
  • java
  • ubuntu
  • vue2
  • wordpress
  • php
  • IOT物联网
  • 项目
  • 故障处理
  • 树莓派
  • 博客存档
  • 未分类
  • 杂项
  • #1742(无标题)
  • 新视野
  • 分类
    • 项目
    • 树莓派
    • 杂项
    • 未分类
    • 新视野
    • 故障处理
    • 博客存档
    • wordpress
    • vue2
    • ubuntu
    • svn
    • sqlite
    • shell脚本
    • redis
    • rabbitmq
    • python-django
    • python
    • proxmox
    • prometheus
    • PostgreSQL
    • php
    • openvpn
    • openssl
    • nginx
    • nfs
    • nextcloud
    • mysql
    • mongo
    • linux
    • kvm
    • kubernetes
    • java
    • IOT物联网
    • httpd
    • GlusterFs
    • git/gitlab
    • freeswitch
    • fastdfs
    • ELK
    • docker
    • centos7
  • 页面
    • #1742(无标题)
  • 友链
      请到[后台->主题设置->友情链接]中设置。
Help?

Please contact us on our email for need any support

Support
    首页   ›   python   ›   正文
python

python常用模块-profile

2022-11-08 11:27:48
1340  0 0
代码性能解析,显示运行时间情况
示例;
import profile

def r():
    print(12222*123344)
def ra():
    print(1)
def rb():
    r()
    ra()
profile.run("rb()")
profile输出
line_profiler 一行一行的分析性能

9 function calls in 0.016 seconds
Ordered by: standard name
ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    1    0.000    0.000    0.000    0.000 :0(exec)
    2    0.000    0.000    0.000    0.000 :0(print)
    1    0.016    0.016    0.016    0.016 :0(setprofile)
    1    0.000    0.000    0.000    0.000 <string>:1(<module>)
    0    0.000             0.000          profile:0(profiler)
    1    0.000    0.000    0.016    0.016 profile:0(rb())
    1    0.000    0.000    0.000    0.000 test1.py:3(r)
    1    0.000    0.000    0.000    0.000 test1.py:5(ra)

    ●ncalls:表示函数调用的次数;
    ●tottime:表示指定函数的总的运行时间,除掉函数中调用子函数的运行时间;
    ●percall:(第一个 percall)等于 tottime/ncalls;
    ●cumtime:表示该函数及其所有子函数的调用运行的时间,即函数开始调用到返回的时间;
    ●percall:(第二个 percall)即函数运行一次的平均时间,等于 cumtime/ncalls;
    ●filename:lineno(function):每个函数调用的具体信息;
    如果需要将输出以日志的形式保存,只需要在调用的时候加入另外一个参数。如 profile.run(“profileTest()”,”testprof”)。
评论 (0)

点击这里取消回复。

欢迎您 游客  

Copyright © 2025 网站备案号 : 蜀ICP备2022017747号
smarty_hankin 主题. Designed by hankin
主页
页面
  • #1742(无标题)
博主
tang.show
tang.show 管理员
linux、centos、docker 、k8s、mysql等技术相关的总结文档
210 文章 2 评论 200969 浏览
测试
测试