10 ms·
In the pure Python cases the 8 bytes per attribute are just pointers. The x, y and z are themselves full-blown objects with all the extra memory overhead that c
by erdewit 7y ago
In the pure Python cases the 8 bytes per attribute are just pointers. The x, y and z are themselves full-blown objects with all the extra memory overhead that comes with it and this is not counted in the article. For example, an int object uses 28 bytes, so three of them already use up more than each of the described container objects.
The Cython and Numpy cases directly store the actual data and this has the larger effect to reduce memory.
- spott 7y agoOn the other hand, the first 256 integers are singletons in python, so they aren't duplicated.
- hermitdev 7y ago0-255 (inclusive) are singletons, just to clarify.
- mswtk 7y agoSlightly pedantic correction: This is a performance optimization in CPython. I wouldn't be surprised if other implementations have something similar, but to my best knowledge, this behaviour isn't part of the standard.
- merlincorey 7y ago> ... but to my best knowledge, this behaviour isn't part of the standard. To the best of my knowledge, Python isn't one such language with a standard, is it?
- ben509 7y agoThe standard is documented in PEPs[1]. CPython is the flagship implementation, and many PEPs discuss it directly, but if you're looking to write another Python, that's where you'd go. https://www.python.org/dev/peps/ https://www.python.org/dev/peps/
- sametmax 7y agoSame for dictionaries ain't it ?