pprofile + matplotlib = Python program profiled as an awesome heatmap!
I use python for scripting, a lot. Python gives me the freedom and flexibility to whip up a functioning code in the least amount of time with least amount of effort. In python even the simplest of things can be implemented in many different ways. For example `a rise to power b` can be achieved using:
1. pow(a, b)
2. a ** b
3. Writing your own function for a rise to b and using it.
which leads to questions like which of it is the best to use if I want to speed up the program. This may not matter much in a script which we rarely use but becomes helpful to reduce times of scripts used in competitive programs where the difference of a second can mean acceptance or time limit exceed.
Obviously, the way to go about it is profiling. There are some really good profilers in python like profile, cProfile, line_profiler, pprofile etc. But profilers print out a ton of data and you have to sift through them to figure out hot zones.
A picture is worth a thousand words
I felt the need for a quick tool which gives me a bird's eye view of the hot zones in a python code without much effort which led me to create pyheat. This is a simple script which takes python file as an input, profiles it one line at a time and displays the entire program as a heat map indicating areas which consumed the most amount of time. Hope this is useful to others too.
Enjoy!
Link to code repository: https://github.com/csurfer/pyheat