The built-in profiler can be told to dump the results of the profile to a "pstats" file. A simple way to do this is to run your code under the module itself, as in:
$ python -mcProfile -o foo.pstats foo.py
This will run your script (foo.py) inside of the profiler and save the profile to the file foo.pstats once the script is done.Once you have a pstats file, you can do some interesting things with it. You can load it into an interactive pstats session with this:
$ python -mpstats foo.pstats
This will allow you to sort and display the profile data in a number of ways.You can also use the third-party gprof2dot script[1] to turn the pstats file into a GraphViz dot file, and thence into a visualization of your code's performance. For example:
$ gprof2dot.py -f pstats foo.pstats | dot -Tpdf -o foo.pdf
That will turn your foo.pstats file into a PDF. I like the PDF format here because it is vectorized, renders quickly (more quickly than SVG, at least), and you can search for specific text in it (which is useful if you have a large profile and want to find a specific function).