Hacker News new | past | comments | ask | show | jobs | submit login
Python memory usage of common types (valuedlessons.com)
32 points by derwiki on Sept 1, 2009 | hide | past | favorite | 3 comments



For large collections of homogenous values, using the array or struct modules is best for memory (and often for speed as well).

Or if math is needed, then numpy arrays are best.

Storing homogenous data in lists/tuples is fine if performance/memusage is not critical, or for small collections (i.e., 90% of use-cases).


It's not mentioned in this article, but Python 2.6 objects have a __sizeof__ method, used by sys.getsizeof():

  >>> help(sys.getsizeof)
  Help on built-in function getsizeof in module sys:

  getsizeof(...)
    getI(object, default) -> int

    Return the size of object in bytes.

http://bugs.python.org/issue2898


This boggled me a bit until I noticed it's a 64-bit system. So an int takes 3 words, which sounds more reasonable.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: