November 15th, 2020 at 8:55 PM
(November 15th, 2020 at 8:35 PM)Thomas Wrote: Python is a great language! Very easy to learn and very powerful. Not the quickest though.
Yep. It is quite slow. One of the slowest languages in existence that isn't web oriented. There are ways to optimize it quite a bit. CPython is the typical way of approaching it, and it takes regular, vanilla python code and compiles to C for near-native performance. I've gotten extremely good speed-up results by using it, and it takes minimal work and can take standard Python programs as well.
They also suggest PyPy, but it doesn't support Numpy or certain other libraries. It ends up having poor results on most programs, but on the ones that do work, it works quite well.
That being said, Python isn't always slower. It is very commonly used in the AI sector, where tensorflow offloads most of the execution. In these cases, tensorflow was compiled in C and runs at native speed. Programs that depend heavily on these sorts of libraries tend to run very fast because the majority of the code executed is compiled within the libraries. Python pushes these libraries heavily. Numpy and OpenCV, among others are also compiled to C and run a lot of code natively, and most programs actually offload quite a bit of their internal execution in this manner.
Otherwise, nobody is really doing intense algorithms raw and vanilla-style in python directly. One day they will consider optimizing it or putting a JIT in place, but until then, it's slower than a turtle on a icy winter day.