5 ms·
Python memory usage of common types
- apu 17y agoFor 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).
- abecedarius 17y agoThis boggled me a bit until I noticed it's a 64-bit system. So an int takes 3 words, which sounds more reasonable.
- yangyang 17y agoIt'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 http://bugs.python.org/issue2898