Chapter 4. C Performance with Cython
Cython is a language that extends Python by supporting the declaration of types for functions, variables, and classes. These typed declarations enable Cython to compile Python scripts to efficient C code. Cython can also act as a bridge between Python and C as it provides easy-to-use constructs to write interfaces to external C and C++ routines.
In this chapter, we will learn the following things:
- Cython syntax basics
- How to compile Cython programs
- How to use static typing to generate fast code
- How to efficiently manipulate arrays using typed memoryviews
- Optimizing a sample particle simulator
- Tips on using Cython in the Jupyter notebook
- The profiling tools available for Cython
While a minimum knowledge of C is helpful, this chapter focuses only on Cython in the context of Python optimization. Therefore, it doesn't require any C background.