Hacker News new | ask | show | jobs
by ForHackernews 4419 days 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-impl...

1 comments

Dynamic 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.