Python may be an excellent language for rapid prototyping and code development, but one thing I often hear people say about using it is that it’s slow to execute.
This is a particular pain point for data scientists and ML engineers, as they often perform computationally intensive operations, such as matrix multiplication, gradient descent calculations or image processing.
Over time, Python has evolved internally to address some of these issues by introducing new features to the language, such as multi-threading or rewriting.
However, Python’s use of the Global Interpreter Lock (GIL) often hamstrung efforts like this.
Many external libraries have also been written to bridge this perceived performance gap between Python and compiled languages such as Java.
Today, I would like to discuss another runtime-enhancing external library, Cython.
If you haven’t heard of Cython, it’s a superset of Python designed to provide C-like performance with code written mainly in Python.
It allows for converting Python code into C code, which can then be compiled into shared libraries that can be imported into Python just like regular Python modules.
This process results in the performance benefits of C while maintaining the readability of Python.
This process results in the performance benefits of C while maintaining the readability of Python.