2014年5月5日 星期一

python3 用profiling測執行時間

Python 有內建 profiling 的工具,叫做 profile,可以透過命令列直接下參數使用:
1
python -m cProfile -s time MODULE.py ARGUMENTS
這樣會執行 MODULE 再將測量結果輸出到螢幕,時間依單一函式執行時間來排序。引用官網的例子,cProfile 的輸出格式如下:
1
2
3
4
5
6
7
8
     2706 function calls (2004 primitive calls) in 4.504 CPU seconds
 
Ordered by: standard name
 
ncalls  tottime  percall  cumtime  percall filename:lineno(function)
    2    0.006    0.003    0.953    0.477 pobject.py:75(save_objects)
 43/3    0.533    0.012    0.749    0.250 pobject.py:99(evaluate)
 ...

沒有留言:

張貼留言