Python is distributed with profiling modules. They describe the run time operation of a pure python program, providing a variety of statistics.

The cProfile module is the recommended module. To execute your program under the control of the cProfile module, a simple form is

$ python -m cProfile -s cumulative mypythonscript.py ncalls tottime percall cumtime percall filename:lineno(function) 16 0.055 0.003 15.801 0.988 __init__.py:1(<module>) 1 0.000 0.000 11.113 11.113 __init__.py:35(extract) 135 7.351 0.054 11.078 0.082 __init__.py:25(iter_extract) 10350736 3.628 0.000 3.628 0.000 {method 'startswith' of 'str' objects} 1 0.000 0.000 2.422 2.422 pyplot.py:123(show) 1 0.000 0.000 2.422 2.422 backend_bases.py:69(__call__) ...

Each column provides information about time execution of every function calls. -s cumulative orders the result by descending cumulative time.