Monday, April 27, 2009

And now I lay me down to sleep...

Daniel Kripke sure must be a thorn in the side of the pharmaceutical industry. The world needs more doctors like him.

Let's hope this is a better century for evidence-based medicine than the last.

Sunday, April 5, 2009

Graphically Visualizing Output from the Python Profiler

Back when I was a teenager just getting my feet wet with programming, I remember sometimes spending hours looking over my code and making incremental changes, trying to figure out why it was slow. Nobody had told me about profilers! These days my first instinct when something is slower than I expect is to try and find some way to profile it, because the bottleneck is probably not where I think it is.

Python's profiler is nice, but mentally grokking the output can be a little obtuse. Thanks to José Fonseca there's a simple and easy way to visualize the output. He's written a script that converts the output from various profilers (including Python's cProfile) into a dot graph. Here's the output from a recent run that shows a single call to deepcopy killing my app's performance:

Using Gprof2Dot on a basic python project is very simple, although you might run into some trouble if you want to use it on Google App Engine. I haven't tried it yet but there's a good response on stackoverflow that might help.

To learn more about Gprof2Dot, visit the Gprof2Dot project page.