天天看點

cProfile——Python性能分析工具

Python自帶了幾個性能分析的子產品:profile、cProfile和hotshot,使用方法基本都差不多,無非子產品是純Python還是用C寫的。本文介紹cProfile。

 例子

<a></a>

運作

運作結果

cProfile——Python性能分析工具

結果分析

    執行了6個函數,總共花費了10.138s,按着運作函數名字排序為結果輸出。

運作腳本

這裡以子產品方式直接儲存profile結果,可以進一步分析輸出結果,運作

結果(随機)

cProfile——Python性能分析工具

可以設定排序方式,例如以花費時間多少排序

cProfile——Python性能分析工具

sort_stats支援以下參數:

1

<code>calls, cumulative, file, line, module, name, nfl, pcalls, stdname, time</code>

pstats子產品還支援互動式

cProfile——Python性能分析工具

本文轉自jihite部落格園部落格,原文連結:http://www.cnblogs.com/kaituorensheng/p/4453953.html,如需轉載請自行聯系原作者