13
當我使用pstats
顯示分析數據時,第一列是每個函數的調用次數。在Python cProfile中,調用計數和原始調用計數有什麼區別?
但是,當我對數據進行排序時,我可以選擇calls
,ncalls
和pcalls
之間的鍵。文檔說calls
和ncalls
是呼叫計數,當pcalls
是原始呼叫計數。正在按calls
或ncalls
排序是一樣的嗎?與pcalls
有什麼不同?
當我使用pstats
顯示分析數據時,第一列是每個函數的調用次數。在Python cProfile中,調用計數和原始調用計數有什麼區別?
但是,當我對數據進行排序時,我可以選擇calls
,ncalls
和pcalls
之間的鍵。文檔說calls
和ncalls
是呼叫計數,當pcalls
是原始呼叫計數。正在按calls
或ncalls
排序是一樣的嗎?與pcalls
有什麼不同?
http://docs.python.org/2/library/profile.html#module-cProfile
我們定義基本意味着呼叫不是通過遞歸誘導。
...當該功能不遞歸,這兩個值是相同的
排序由calls
或ncalls
是一樣的。
當存在在第一列中兩個數(例如,第43/3號),則後者是原始的呼叫的數量,而前者是呼叫的實際數目。注意,當該功能不進行遞歸,這兩個值是相同的,並且僅 打印唯一的附圖:
In [43]: def a(i):
....: if i == 0:
....: return
....: a(i-1)
....:
In [54]: %prun a(0)
ncalls tottime percall cumtime percall filename:lineno(function)
1 0.000 0.000 0.000 0.000 <ipython-input-43-25b7f3d268b8>:1(a)
In [55]: %prun a(1)
ncalls tottime percall cumtime percall filename:lineno(function)
2/1 0.000 0.000 0.000 0.000 <ipython-input-43-25b7f3d268b8>:1(a)
In [56]: %prun a(3)
ncalls tottime percall cumtime percall filename:lineno(function)
4/1 0.000 0.000 0.000 0.000 <ipython-input-43-25b7f3d268b8>:1(a)