Is there any way to minimize str()/unicode() objects memory usage [Python 2.6.4] ?

dmtr dchichkov at gmail.com
Sat Aug 7 09:33:54 CEST 2010


Correction. I've copy-pasted it wrong! array.array('i', (i, i+1, i+2, i
+3, i+4, i+5, i+6)) was the best.

>>> for i in xrange(0, 1000000): d[unicode(i)] =  (i, i+1, i+2, i+3, i+4, i+5, i+6)
1000000 keys, ['VmPeak:\t  224704 kB', 'VmSize:\t  224704 kB'],
4.079240 seconds, 245143.698209 keys per second

>>> for i in xrange(0, 1000000): d[unicode(i).encode('utf-8')] =  (i, i+1, i+2, i+3, i+4, i+5, i+6)
1000000 keys, ['VmPeak:\t  201440 kB', 'VmSize:\t  201440 kB'],
4.985136 seconds, 200596.331486 keys per second

>>> for i in xrange(0, 1000000): d[unicode(i).encode('utf-8')] =  array.array('i', (i, i+1, i+2, i+3, i+4, i+5, i+6))
1000000 keys, ['VmPeak:\t  125652 kB', 'VmSize:\t  125652 kB'],
3.572301 seconds, 279931.625282 keys per second

-- Dmitry




More information about the Python-list mailing list