(0|1) log

pprofile + matplotlib = python program profiled as an awesome heatmap

written on Monday, February 6, 2017

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:

which leads to questions like:

This may not matter much in a script which we rarely use or even the ones we use on a daily basis. But, these questions becomes extremely important in case of 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.

As a famous English idiom goes,

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 command line tool 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.

Where to find the code ?

https://github.com/csurfer/pyheat

This entry was tagged profiling and python