Profiling Cython
Cython provides a feature, called annotated view, that helpsĀ find which lines are executed in the Python interpreter and which are good candidates for ulterior optimizations.Ā We can turn this feature on by compiling a Cython file with the -a
option. In this way, Cython will generate an HTML file containing our code annotated with some useful information. The usage of theĀ -a
option is as follows:
$ cython -a cevolve.pyx $ firefox cevolve.html
The HTML file displayed in the following screenshot shows our Cython file line by line:
Each line in the source code can appearĀ in different shades of yellow. A more intenseĀ color corresponds to moreĀ interpreter-related calls, while white lines are translated to regularĀ C code. Since interpreter calls substantially slow down execution, the objective is to make the function body as white as possible. By clicking on any of the lines, we can inspect the code generated by the Cython compiler. For example, the v_y = x/norm
line checks that the...