Is python getting faster?

A couple of years ago I heard about the efforts to make python more efficient and improve its performance. As a developer who regularly uses python, it was something that is “long overdue” in my opinion.
Cut short to 2022, python released version 11 in beta (`rc2`) featuring significant performance improvements, going above 20% in some cases.
A bit skeptical on these claims, I wanted to see it for myself. To test it out, I decided to employ the most naive strategy possible and use simplest operations as claimed in python docs instead of creating any algorithm around them.
In this blog, I show what I found!
SPOILER ALERT: It actually is faster!! 😃
Environment Setup
To configure the environment, I have used exact same environment with all the testing versions of python installed, with following configuration:
- Environment: Docker
- Operating System: Ubuntu 22.04.1 LTS
- CPUs Allocated: 1 CPU
- Python 3.8.14: (default, Sep 8 2022, 00:02:07)
- Python 3.9.14: (main, Sep 7 2022, 23:43:48)
- Python 3.10.6: (main, Aug 10 2022, 11:40:04) [GCC 11.3.0] on linux
- Python 3.11.0rc2: (main, Sep 13 2022, 15:08:15) [GCC 11.2.0] on linux
Test Configuration
To follow my goal as mentioned above, I decided to use small operations mentioned in python documentation and measure improvements on them. For this, I created 4 different tests:
NOTE: The motive of following tests is to just measure the performance difference between each version of the language.
Test 1 — `len` and `str` functions
for i in range(100000):
data.append(i*195)def len_test():
for x in data:
len(str(x))
Test 2 — `mul` operation
for i in range(100000):
data.append(i*195)def mul_test():
for x in data:
x*x
Test 3 — array assignment (subscript operation)
for i in range(100000):
data.append(i*195)def mul_test():
for i in range(len(data)):
data[i] = 45 + i
Test 4 — list comprehension with zip
arr1 = np.random.rand(100000).tolist()
arr2 = np.random.rand(100000).tolist()def mul_test():
[a * b for a, b in zip(arr1, arr2)]
Results

Conclusion
To my happy surprise, there is a much noticeable performance improvement for these basic operations in python 3.11 as compared to previous versions. Percentage wise, I have noticed up-to 45% improvement in Python 3.11 in above tests as compared to previous version (Python 3.10).
Python 3.11 is still pre-release and will be come out with stable final release in early October, 2022.
Have you tried our Python 3.11 yet? If you have also noticed improvements in your day to day python usage, do leave a comment.