Efficient Programming cProfile Performance Analysis

Write code often hear some terms, such as performance analysis, code tuning.

cProfile tuning python code is a tool capable of counting throughout the implementation of the code, the time consumed and the number of each function call.

 

This tool, although very common, but no need to spend too much time studying this tool, you can achieve simple to use, so I am here simply to record core usage.

 

Two ways

cProfile.run ( ' FUNC (Arg) ' )      # tuning function, the script used in the 
Python -m cProfile mine myscript.py (-s ziduan)     # tuning script, the command line using

 

Output Interpreter

        9891015 function calls (9843181 primitive calls) in 12.791 seconds

   Ordered by: standard name

   ncalls  tottime  percall  cumtime  percall filename:lineno(function)
        1    0.000    0.000   12.791   12.791 <string>:1(<module>)
        1    0.037    0.037    0.966    0.966 AccOverstep.py:13(AccOverstep)
        2    0.166    0.083    9.534    4.767 DataPreprocessing.py:27(dists)
        1    0.003    0.003    6.252    6.252 DataPreprocessing.py:38(DataPreprocessing)
    10909    0.004    0.000    0.167    0.000 _methods.py:34(_sum)
       10    0.000    0.000    0.000    0.000 _methods.py:45(_all)
    42360    0.071    0.000    0.092    0.000 _methods.py:48(_count_reduce_items)
    42360    0.201    0.000    0.678    0.000 _methods.py:58(_mean)

 

A total of 9,891,015 times a function call, the original call is 9,843,181 times, on behalf of the original call does not contain recursive calls.

ncalls function is the number of calls 

tottime function total running time, remove the function call a function of time 

percall a function of the average running time is equal tottime / ncalls 

cumtime function total run time, including calling a function of time 

percall a function of the average running time is equal cumtime / ncalls 

filename: Name lineno (function) function where the line number of the function, the function name
 

 

 

References:

https://blog.csdn.net/u010453363/article/details/78415553

Guess you like

Origin www.cnblogs.com/yanshw/p/11593255.html