PyProfilers is collection of wrapper functions for various Python profilers which aims to make profiling more convenient.
Install and update using pip:
pip install -U pyprofilers
import pyprofilers as pp
Use the standard Python cProfile to list
the cumulative time spent in the function
func and all its subfunctions:
@pp.profile(sort_by='cumulative', out_lines=30) def func(): ...
sort_bycan be used to sort the results according to the supplied criteria. All criterias can be found here.
out_linescontrols the number of lines in results. Use
Noneor ommit the arugment to show all.
Use the line_profiler to list time spent within each line of
@pp.profile_by_line(exit=1) def func(): ...
True to stop the execution after the first call to
func returns. This is useful if
func is called multiple times to
avoid the repeated output of the profiler statistics.
To just time the execution of a function use the
@pp.simple_timer(num=1) def func(): ...
num argument can be used to specify how often the function should be executed.