3 ms·
Mmm I don't quite get why sys.getsizeof is reporting a bigger size in the slotted class, it should be the other way around according to that post. Test code at
by omegote 13y ago
Mmm I don't quite get why sys.getsizeof is reporting a bigger size in the slotted class, it should be the other way around according to that post.
Test code at: http://codepad.org/wlb53BLf http://codepad.org/wlb53BLf not sure if I'm missing something...
- deleted 13y ago[deleted]
- benhoyt 13y agoPer the Python 3 docs (for some reason not in the Python 2 docs, but the same holds): "Only the memory consumption directly attributed to the object is accounted for, not the memory consumption of objects it refers to." Most of the space for the NonSlotted version is in the __dict__, and if you print the size of ni.__dict__ you'll probably get a couple of hundred bytes. There are better, recursive ways to get the real size of a Python object in memory, for example see: http://pythonhosted.org/Pympler/asizeof.html#asizeof http://pythonhosted.org/Pympler/asizeof.html#asizeof
- omegote 13y agoNice, just used pympler.asizeof and it reported that the slotted version has about 22% of the size of the non-slotted version.
- simgidacav 13y agoI tried with this: http://pastebin.com/nfqtDUiW http://pastebin.com/nfqtDUiW Try comment and un-comment the __slot__. You can measure the program memory footprint using pmap -x <PID> where <PID> is obtained using pgrep python ...more than one python process? cat /proc/<PID>/cmdline | xargs -0 echo