加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

【Python】【程序分析器】关于Python Profilers性能分析器

发布时间:2020-12-17 01:23:39 所属栏目:Python 来源:网络整理
导读:转载自:http://www.cnblogs.com/btchenguang/archive/2012/02/03/2337112.html p style="margin:10px auto; padding-top:0px; padding-bottom:0px; color:rgb(68,68,68); font-family:tahoma,arial,sans-serif; font-size:12px; line-height:1.5!important"

转载自:http://www.cnblogs.com/btchenguang/archive/2012/02/03/2337112.html

<p style="margin:10px auto; padding-top:0px; padding-bottom:0px; color:rgb(68,68,68); font-family:tahoma,arial,sans-serif; font-size:12px; line-height:1.5!important">
想了解一下python的性能调试方法,结果就看到这一篇文章,想翻译下来作个记录


<p style="margin:10px auto; padding-top:0px; padding-bottom:0px; color:rgb(68,sans-serif; font-size:12px; line-height:1.5!important">
原文来自于:<a target="_blank" title="http://docs.python.org/library/profile.html?highlight=profile#cProfile" href="http://docs.python.org/library/profile.html?highlight=profile#cProfile" rel="nofollow" style="margin:0px; padding:0px; color:rgb(68,68)">http://docs.python.org/library/profile.html?highlight=profile#cProfile


<h2 style="margin:10px 0px; padding:0px; font-size:21px; line-height:1.5; color:rgb(68,sans-serif">

  1. 介绍性能分析器
    <p style="margin:10px auto; padding-top:0px; padding-bottom:0px; color:rgb(68,sans-serif; font-size:12px; line-height:1.5!important">
    profiler是一个程序,用来描述运行时的程序性能,并且从不同方面提供统计数据加以表述。Python中含有3个模块提供这样的功能,分别是cProfile,profile和pstats。这些分析器提供的是对Python程序的确定性分析。同时也提供一系列的报表生成工具,允许用户快速地检查分析结果。


    <p style="margin:10px auto; padding-top:0px; padding-bottom:0px; color:rgb(68,sans-serif; font-size:12px; line-height:1.5!important">
    Python标准库提供了3个不同的性能分析器:


    <ol style="margin:0px; padding:0px 0px 0px 40px; color:rgb(68,sans-serif; font-size:12px">
    <li style="margin:0px 0px 1em; padding:0px; list-style:decimal">cProfile,推荐给大部分的用户,是C的一个扩展应用,因为其合理的运行开销,所以适合分析运行时间较长的。是基于lsprof。
  2. <li style="margin:0px 0px 1em; padding:0px; list-style:decimal">profile,一个纯python模块,它的接口和cProfile一致。在分析程序时,增加了很大的运行开销。如果你想扩展profiler的功能,可以试着继承这个模块<li style="margin:0px 0px 1em; padding:0px; list-style:decimal">hotshot,一个试验性的c模块,关注减少分析时的运行开销,但是是以需要更长的数据后处理的次数为代价。不过这个模块不再被维护,也有可能在新的python版本中被弃用。

<h2 style="margin:10px 0px; padding:0px; font-size:21px; line-height:1.5; color:rgb(68,sans-serif">
  • 使用方法
    <div style="margin:0px; padding:0px; color:rgb(68,sans-serif; font-size:12px; line-height:1.5!important">
    <div id="highlighter_16630" class="syntaxhighlighter py" style="padding:0px; width:715px; margin:1em 0px!important; position:relative!important; overflow:auto!important; font-size:1em!important; line-height:1.5!important">
    <table border="0" cellpadding="0" cellspacing="0" style="border-collapse:collapse; border-spacing:0px; border:1px solid silver; width:715px; word-break:break-word; margin:0px!important; padding:0px!important; background:none!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; font-family:Consolas,"Bitstream Vera Sans Mono","Courier New",Courier,monospace!important; font-size:12px!important; min-height:auto!important">
    <tbody style="margin:0px!important; padding:0px!important; background:none!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-size:12px!important; min-height:auto!important">
    <tr style="margin:0px!important; padding:0px!important; background:none!important; border:0px!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-size:12px!important; min-height:auto!important">
    <td class="gutter" style="padding:3px; border:1px solid silver; border-collapse:collapse; margin:0px!important; background:none!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:35px!important; font-family:Consolas,monospace!important; min-height:auto!important; color:rgb(175,175,175)!important">
    <div class="line number1 index0 alt2" style="margin:0px!important; padding:0px 0.5em!important; background:none rgb(244,244,244)!important; border-width:0px 2px 0px 0px!important; border-top-style:initial!important; border-right-style:solid!important; border-bottom-style:initial!important; border-left-style:initial!important; border-top-color:initial!important; border-right-color:rgb(108,226,108)!important; border-bottom-color:initial!important; border-left-color:initial!important; bottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.5!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; text-align:right!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-size:12px!important; min-height:auto!important">
    1
  • (编辑:李大同)

    【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

      推荐文章
        热点阅读