Python Programming/Performance

From Wikibooks, open books for an open world
Jump to navigation Jump to search

Since Python is an interpreted language in its most commonly used CPython implementation, it is many times slower in a variety of tasks than the most commonly used compiled non-managed languages such as C and C++; for some tasks, it is more than 100 times slower. CPython seems to be on par with Perl, another interpreted language, slower on some tasks, faster on other tasks.

Performance can be measured using benchmarks. Benchmarks are often far from representative of the real-world usage and have to be taken with a grain of salt. Some benchmarks are outright wrong in that non-idiomatic code is used for a language, yielding avoidably low performance for the language.

PyPy is a just-in-time (JIT) compiler that often runs faster than CPython. Another compiler that can lead to greater speeds is Numba, which works for a subset of Python. Yet another compiler is Cython, not to be confused with CPython.

External links[edit | edit source]