3 ms·
The Bitter Truth: Python 3.11 vs. Cython vs. C++ Performance for Simulations
- Qem 4y agoThe big omission in this post is PyPy. I ran the pure unmodified python version in my computer. PyPy runs it about 10x faster when compared to CPython 3.11: [user@fedora Documents]$ python3 Python 3.11.1 (main, Dec 7 2022, 00:00:00) [GCC 12.2.1 20221121 (Red Hat 12.2.1-4)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> quit() [user@fedora Documents]$ for i in {1..5}; do time python3 example_02.py; done 27 113 393 real 0m10,486s user 0m10,445s sys 0m0,011s 22 173 277 real 0m12,177s user 0m12,133s sys 0m0,007s 30 126 433 real 0m9,608s user 0m9,565s sys 0m0,012s 0 2294 186 real 0m46,340s user 0m46,183s sys 0m0,010s 31 137 410 real 0m10,171s user 0m10,121s sys 0m0,011s [user@fedora Documents]$ pypy3 Python 3.9.12 (fa9372ba2f8a, Dec 03 2022, 08:47:37) [PyPy 7.3.9 with GCC 12.2.1 20221121 (Red Hat 12.2.1-4)] on linux Type "help", "copyright", "credits" or "license" for more information. >>>> quit() [user@fedora Documents]$ for i in {1..5}; do time pypy3 example_02.py; done 0 2311 203 real 0m3,370s user 0m3,317s sys 0m0,038s 27 114 363 real 0m0,989s user 0m0,954s sys 0m0,029s 29 81 464 real 0m1,019s user 0m0,993s sys 0m0,020s 23 135 355 real 0m0,888s user 0m0,859s sys 0m0,024s 27 137 324 real 0m1,012s user 0m0,971s sys 0m0,035s [user@fedora Documents]$ Python doesn't look so bad after all, if you pick a implementation that draws a lot from the 30+ years of work on speeding up dynamic languages pioneered by Smalltalk and Self communities.