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

garabik-news-2005-05 at kassiopeia.juls.savba.sk garabik-news-2005-05 at kassiopeia.juls.savba.sk
Sat Aug 7 10:04:48 EDT 2010


dmtr <dchichkov at gmail.com> wrote:
> I guess with the actual dataset I'll be able to improve the memory
> usage a bit, with BioPython::trie. That would probably be enough
> optimization to continue working with some comfort. On this test code
> BioPython::trie gives a bit of improvement in terms of memory. Not
> much though...
> 
>>>> d = dict()
>>>> 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))
>

Using struct.pack('7i',i, i+1, i+2, i+3, i+4, i+5, i+6) instead of 
array.array gives 20% improvement in time with (not surprisingly) 
the same memory usage.

-- 
 -----------------------------------------------------------
| Radovan Garabík http://kassiopeia.juls.savba.sk/~garabik/ |
| __..--^^^--..__    garabik @ kassiopeia.juls.savba.sk     |
 -----------------------------------------------------------
Antivirus alert: file .signature infected by signature virus.
Hi! I'm a signature virus! Copy me into your signature file to help me spread!



More information about the Python-list mailing list