profile and pstats

profile 对函数运行时间排序

import profile
profile.run('f()','result')   #result 为保存的结果,不能直接查看,使用pystats查看

或命令行:

python -m profile -s time example.py -o result

pstats 对保存的结果查看

import pstats
p=pstats.Stats('result')
p.sort_stats('time').print_stats(5)   #运行时间前5行
p.sort_stats('cumulative').print_stats(0.1)   #总共时间前10%。

和单元测试unittest合并

 if __name__ == '__main__':
    import profile
    profile.run('unittest.main()','result')
    import pstats
    p=pstats.Stats('result')
    p.sort_stats('time').print_stats(10)
    unittest.main()
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,026评论 19 139
  • linux资料总章2.1 1.0写的不好抱歉 但是2.0已经改了很多 但是错误还是无法避免 以后资料会慢慢更新 大...
    数据革命阅读 12,242评论 2 33
  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 173,726评论 25 709
  • Spring Boot 参考指南 介绍 转载自:https://www.gitbook.com/book/qbgb...
    毛宇鹏阅读 46,975评论 6 342
  • 致家长和专业人士 本课程的目的是帮助少男少女消弭青春期独有的风险并在此期间有切实的收获——发展和提高他们健康自信的...
    快乐筱竹阅读 304评论 0 0