"don’t suffer Python’s terrible per-object overhead"
Yet another example of where I'd love to see some numbers.
Yet another example of where I'd love to see some numbers.
kragen@inexorable:~$ python
Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)
[GCC 4.4.5] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import os, commands
>>> print commands.getoutput('ps u %s' % os.getpid())
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
kragen 20823 0.3 0.1 9636 3780 pts/4 S+ 14:00 0:00 python
>>> x = [{} for ii in range(1000*1000)]
>>> print commands.getoutput('ps u %s' % os.getpid())
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
kragen 20823 10.8 7.7 168176 159756 pts/4 S+ 14:00 0:02 python
>>> (159756-3780)*1024/(1000.0*1000)
159.719424
So the baseline is about 160 bytes per dict. Objects, by default, are built on dicts. Objects with __slots__ can be a little more efficient.