效果
以熱力圖的形式直觀地顯示代碼行的性能影響,顏色越深占用時間越長。

安裝與使用
?? 安裝:
pip install py-heat
?? 簡單的命令行使用:
pyheat --pyfile <path_to_python_file>
簡單分析
是一個單文件應用,一共155行,簡潔明了,使用 pprofile性能分析庫和matplotlib.pyplot畫圖,將二者組合的創(chuàng)意很好。畫圖形式值得學習,利用matplotlib.pyplot.pcolor(example)和matplotlib.pyplot.colorbar以及matplotlib.pyplot.text實現效果。
不過,在win10上測試,pprofile的分析不是很穩(wěn)定。

畫圖
簡單測試
測試代碼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()
命令行執(zhí)行pyheat --pyfile threads.py測試結果(win10, py3.5):
