Member-only story
Cython for absolute beginners: 30x faster code in two simple steps
Easy Python code compilation for blazingly fast applications
Python is very easy to work with; clear syntax, the interpreter and duck-typing allow you to develop very quickly. There are some downsides though: if you don’t have to adhere to a strict syntax, then Python has to do some extra work to get your code to run, causing some functions e.g. to execute very slowly because it has to do all those checks again and again.
Combine the ease and speed of developing with Python with the speed of C: the best of both worlds
In this article we’ll take a “slow” function from a vanilla Python project and make it 30x faster. We do this by using a package called Cython that will convert our Python-code to a compiled, superfast piece of C-code that we can directly import into our project again.
A package called CythonBuilder will automatically Cythonize Python code for us in just 2 steps. With CythonBuilder we’ll Cythonize a function from an example project we’ll define below. Let’s code!
But first..
For those unfamiliar with Cython and CythonBuilder we’ll answer some exploratory questions. Then we’ll define…