2013-04-04 65 views

回答

13

http://docs.python.org/2/library/profile.html#module-cProfile

我們定義基本意味着呼叫不是通過遞歸誘導。

...當該功能不遞歸,這兩個值是相同的

排序由callsncalls是一樣的。


當存在在第一列中兩個數(例如,第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) 
相關問題