O'Reilly logo

Python High Performance Programming by Gabriele Lanaro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Profiling Cython

Cython gives us a wonderful tool to quickly find the slow spots due to the Python interpreter—a feature called annotated view. We can turn on this feature by compiling a Cython file with the -a option, using the following command line. Cython will generate a HTML file containing our code annotated with some useful information:

$ cython -a cevolve.pyx
$ google-chrome cevolve.html

The HTML file displayed in the following screenshot shows our Cython file line-by-line:

Profiling Cython

Each line has a background color in different shades of yellow; an intense color means that the code has a lot of interpreter-related calls, while white lines gets translated ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required