## Benchmarking the new and impressive Python 3.11

Python is one of the most used scripting languages in data science (DS) and machine learning (ML). According to ‘PopularitY of Programming Languages’ Python is the most searched language on Google. Next to being a great *glue *language to connect various DS/ML solutions together, it has many libraries to virtually do anything with data.

In about a month we get a fresh new yearly release of Python: version 3.11. I am quite excited about this new version as the main feature for this version is a significant increase in speed.

On LinkedIn I have already seen a couple of post of people testing the new version and their results were stunning. But the best method to get a feeling on how fast Python 3.11 truly is, is to run the tests yourself.

In this post I will share my step-by-step analysis of Python 3.11. All code is available on my github page.

Benchmarking a programming language is not trivial at all. When you read *x *is faster than *y*, you should always take the result with a grain of salt. One implementation of an algorithm can be better of *x* while another is better on *y*. For our benchmark it is a bit simpler as we are testing Python against Python, but we might have selected elements from the language that are only marginally effected. With this in mind, I want to present the algorithm I used to benchmark: the estimation of Pi using a Monte Carlo method.

The idea of this algorithm is simple but the first time a saw it during some mathematics course at the University it blew my mind. We have a square of size *2r* and in this square we fit a circle of radius *r*. Now we take a random number generator that generates numbers on a plane: *<-r, r>, <-r, r>*. The ratio between the points that are on the circle and the points on the square (read: all points) is an approximation of the ratio of area, which we can use to approximate Pi. This is a bit more clear in the equation:

In Python, I have split up the actual estimation from a testing script such that I can repeat the test and take the average. Not shown here, but I have also parametrized the script using *Argparse*, a standard library to parse arguments from the command line interface (CLI). The Python code looks like this: