Member-only story
Write Your Own C-extension to Speed Up Python by 100x
How to write, compile, package and import your own, superfast C-module into Python
Python is a fantastic language that is very easy to pick up, very fast to develop with, and very clear to read. All these benefits come at a cost: Python is pretty slow compared to some other languages. I can strongly recommend reading this article before continuing to get a clear idea of the problem we’re trying to solve. The goal of this article is to answer this question:
How can we combine Python’s ease of development without sacrificing speed?
The sarcastic answer is to rewrite the project in another language but that’s not what we’re here for. You’re a Python programmer, already have a lot of programs written in Python, and just want to speed up a small part of it. Also: if you are used to writing in Python, the transition to another language like C# or Java might be pretty rough.
We’ll combine the best of two worlds: we extend our program with a small module that we write in C. Python programmers can just import this package, don’t have to know a single line of C, and can still enjoy the 100x speed increase.

