Better Programming

Advice for programmers.

Member-only story

Speed Up Your Python Codebases With C Extensions

Nicholas Obert
Better Programming
Published in
6 min readJul 19, 2021

--

Photo by PAUL SMITH on Unsplash

Python, being both easy and powerful, has become one of the most popular programming languages. Nonetheless, it sometimes lacks the much-valued speed of statically typed and precompiled programming languages like C and Java.

Why is Python Slow?

As you may know, Python is generally implemented through an interpreter. This can cause the code execution to be rather slow compared to languages, like C and Java, with compiled implementations and whose source code is compiled in advance into machine/byte code. However, this topic is beyond the scope of the article.

How Can You Speed Up Python Code?

Unless you have to perform computationally heavy operations, Python’s speed is not usually a problem. This is where C extensions come in handy.

C extensions are a way to code functions in C, compile them into a Python module and use them in your source code as a normal Python library.

--

--