美文网首页python开发程序员@IT·互联网
直观热力图视化python代码性能分析

直观热力图视化python代码性能分析

作者: treelake | 来源:发表于2017-02-10 11:23 被阅读614次

    来源:github - csurfer/pyheat
    用途:可以学习的简单开源代码

    效果

    以热力图的形式直观地显示代码行的性能影响,颜色越深占用时间越长。


    安装与使用

    ⭐️ 安装:
    pip install py-heat

    ⭐️ 简单的命令行使用:
    pyheat --pyfile <path_to_python_file>

    简单分析

    是一个单文件应用,一共155行,简洁明了,使用 pprofile性能分析库和matplotlib.pyplot画图,将二者组合的创意很好。画图形式值得学习,利用matplotlib.pyplot.pcolor(example)和matplotlib.pyplot.colorbar以及matplotlib.pyplot.text实现效果。
    不过,在win10上测试,pprofile的分析不是很稳定。

    画图

    简单测试

    测试代码threads.py

    #!/usr/bin/env python
    import threading
    import time
    
    def func():
      time.sleep(1)
    
    def func2():
      pass
    
    t1 = threading.Thread(target=func)
    t2 = threading.Thread(target=func)
    t1.start()
    t2.start()
    (func(), func2())
    t1.join()
    t2.join()
    

    命令行执行pyheat --pyfile threads.py测试结果(win10, py3.5)

    其它

    python性能分析工具

    相关文章

      网友评论

      本文标题:直观热力图视化python代码性能分析

      本文链接:https://www.haomeiwen.com/subject/bargittx.html