3 ms·
In general, Python is slow (compared to C or whatever) because of excessive memory allocation and overuse of hash maps. PyPy probably manages to optimize the h
by qznc 9y ago
In general, Python is slow (compared to C or whatever) because of excessive memory allocation and overuse of hash maps.
PyPy probably manages to optimize the hash map/method call lookups for these small programs, which explains the speedups. Removing memory allocations is still hard.
The D language provides finer mechanisms to control memory and data structures. This makes the language larger, but enables you to optimize if it becomes necessary.
Still, I agree and I would like to see a Python expert to optimize it.
- dom0 9y ago> In general, Python is slow (compared to C or whatever) because of excessive memory allocation and overuse of hash maps. Python is a highly dynamic language with an API (towards both Python and C) that is very invasive. These two things, taken together, make optimizing the interpreter extremely difficult, because practically all of it can be modified or introspected. CPython being implemented largely as a hashtable-interpreter is only one facet to its performance. Perhaps a talk recommendation: https://www.youtube.com/watch?v=qCGofLIzX6g&list=PLRdS-n5seLRqszBqVDF342RMlCWgOTm6q&index=11 https://www.youtube.com/watch?v=qCGofLIzX6g&list=PLRdS-n5seL...