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

Chris the Multi-Agent Guy
Agents and Robots
Published in
15 min readDec 19, 2022

--

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

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:

--

--

Chris the Multi-Agent Guy
Agents and Robots

Join me on my journey as a Software Engineer, Artist, and Geek, exploring the fascinating worlds of multi-agent simulations and machine learning. Follow me.