3 ms·
Python integers are represented like any other data type: a pointer to a PyObject. In the specific case of small integers, they are recycled from a pool of know
by frankreyes 3y ago
Python integers are represented like any other data type: a pointer to a PyObject. In the specific case of small integers, they are recycled from a pool of known instances, so we save the malloc() call for those. But the penalty still exists for indirections and cache trashing and CPU predictions, and so on...
It has to do that 63 bit integers, like Lua and V8 JS, they are much faster, because no malloc() or pointer indirection is required to do 1234+5678. It's just a few CPU instruction. In Python, it's like 100.
- SushiHippie 3y agoGot it, thanks!