17 ms·
Python statically allocates small integers (-5 to 256), so you're not actually creating a new object unless you're creating one outside that range. http://www.
by ForHackernews 13y ago
Python statically allocates small integers (-5 to 256), so you're not actually creating a new object unless you're creating one outside that range.
http://www.laurentluce.com/posts/python-integer-objects-implementation/ http://www.laurentluce.com/posts/python-integer-objects-impl...
- theseoafs 13y agoDynamic allocation isn't the only cost there -- a cost that's just as big when you're doing number crunching in Python is cache efficiency. If every number is on the heap, and every number in Python is ~20 bytes long, you're going to have caching problems, even if your numbers only ever range from -5 to 256.