運作:python -m cProfile t12.py,列印結果:

其中,輸出每列的具體解釋如下:(http://xianglong.me/article/analysis-python-application-performance-using-cProfile/)
ncalls:表示函數調用的次數;
tottime:表示指定函數的總的運作時間,除掉函數中調用子函數的運作時間;
percall:(第一個percall)等于 tottime/ncalls;
cumtime:表示該函數及其所有子函數的調用運作的時間,即函數開始調用到傳回的時間;
percall:(第二個percall)即函數運作一次的平均時間,等于 cumtime/ncalls;
filename:lineno(function):每個函數調用的具體資訊;
另外,上面分析的時候,排序方式使用的是函數調用時間(cumulative),除了這個還有一些其他允許的排序方式:calls, cumulative, file, line, module, name, nfl, pcalls, stdname, time等
<code># 增加排序方式</code>
<code>python -m cProfile -s cumulative </code><code>t2</code><code>.py #按照cumulative排序</code>