The Bitter Truth: Python 3.11 vs Cython vs C++ Performance for Simulations

1 min read Original article ↗

Chris the Multi-Agent Guy

A speed comparison using a scientific simulation. Is Python finally ready for this task?

Press enter or click to view image in full size

Even the fastest system is slow using the wrong computer language. Cheetah by Magda Ehlers, Pexels

Introduction

This article compares various approaches to speed up Python. However, it should be clear in advance that C++ is still faster than Python. The question is, by how much?

The article is tailored for Data Scientists and persons with domain knowledge and Python experience interested in results gained from a simulation. It shows what tools are available, how to measure performance gains, and what best practices are.

The article demonstrates the current state of Python's performance using one example only (a dynamic Lagrangian simulation). It is not a rigorous comparison.

The Simulation

Over the last few years, not only the speed of computers has increased. Python has become the dominant language in data science thanks to its simplicity and large package ecosystem.

As an example of a scientific simulation, we look at the multi-agent simulation presented in more detail in this earlier article. The output of the simulation is shown in this video: