2011-08-15 10 views
23

tôi chạy này:Làm cách nào để đọc đầu ra của lệnh IPython% prun (profiler)?

In [303]: %prun my_function() 
     384707 function calls (378009 primitive calls) in 83.116 CPU seconds 

    Ordered by: internal time 

    ncalls tottime percall cumtime percall filename:lineno(function) 
    37706 41.693 0.001 41.693 0.001 {max} 
    20039 36.000 0.002 36.000 0.002 {min} 
    18835 1.848 0.000 2.208 0.000 helper.py:119(fftfreq) 

--snip--

gì mỗi tottime, percall, cumtime? ncalls khá rõ ràng (số lần hàm được gọi). My đoán là thời gian tottime là tổng thời gian dành cho chức năng, không bao gồm thời gian trong các cuộc gọi hàm của chính nó; percall là ???; cumtime là tổng thời gian dành cho cuộc gọi hàm bao gồm cả thời gian trong các cuộc gọi hàm của riêng nó (nhưng tất nhiên, trừ việc tính hai lần). docs không quá hữu ích; Tìm kiếm của Google cũng không giúp ích gì.

Trả lời

24

Nó chỉ là một wrapper thuận tiện cho việc lập hồ sơ riêng của Python, tài liệu cho là ở đây:

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

Trích dẫn:

ncalls 
    for the number of calls, 
tottime 
    for the total time spent in the given function (and excluding time made in calls to sub-functions), 
percall 
    is the quotient of tottime divided by ncalls 
cumtime 
    is the total time spent in this and all subfunctions (from invocation till exit). This figure is accurate even for recursive functions. 
percall 
    is the quotient of cumtime divided by primitive calls