Fredrik Gustafsson and Viktor Holmberg

Gradually typed Python using Cython

Abstract

In this report Cython, an experimental programming language which adds functionality to Python was studied. One of the functionalities added by Cython is optional static type annotations. How these optional static type declarations affect performance is the main focus of this report. The effect of these type annotations on type safety and software design aspects of Python was also studied, but to a lesser extent.

To establish how static type annotations affect performance three test cases were designed. These test cases were then gradually typed in a number of versions with different amounts of static typing. Finally, the execution times of the different versions were measured.

It was found that gradual typing using Cython is a excellent optimization strategy for some Python code, particularly numeric calculations. However, Cythons gradually typed type system can not fully be considered an alternative to popular staticly typed languages with respect to software design considerations.