oplaTech About Teaching Archive
Oplatek's external memory

Python Profiling and speed up

I just watched a quite nice tutorial about the "High performance Python". The task was to generate Mandelbrot Image of 1000x1000 pixels. Below you can find several tools and commands which I have used by following the tutorial (just for C Python).

bash $ python -m cProfile -o rep.prof pure_python.py 1000 1000 # generates rep.prof

ipython $ import pstats
ipython $ p = pstats.Stats('rep.prof')
ipython $ p.sort_stats('cumulative').print_stats(10)
.... # some output
ncalls tottime percall cumtime percall filename:lineno(function)
.... # many (10) similar lines
10173 0.059 0.000 0.059 0.000 {range}
.... # some end of output

# runsnake visualize table
bash $ runsnake rep.prof

cp pure_python.py pure_python_added-decoration-profile.py

# I edited pure_python_added-decoration-profile.py
# and added @profile decorater to funtion
# which I want profile line by line
kernprof.py -l -v pure_python_added-decoration-profile.py 1000 1000