Re: List size versus list allocation

2010-05-02 Thread Steven D'Aprano
On Sun, 02 May 2010 18:07:31 +0200, Christian Heimes wrote: >> I'm interested in gathering some statistics on this, and to do so I >> need a way of measuring the list's logical size versus its actual size. >> The first is easy: it's just len(list). Is there some way of getting >> the allocated siz

Re: List size versus list allocation

2010-05-02 Thread Peter Otten
Christian Heimes wrote: def slots(lst): > ... return (sys.getsizeof(lst) - sys.getsizeof([])) / D'oh! Peter -- http://mail.python.org/mailman/listinfo/python-list

Re: List size versus list allocation

2010-05-02 Thread Christian Heimes
I'm interested in gathering some statistics on this, and to do so I need a way of measuring the list's logical size versus its actual size. The first is easy: it's just len(list). Is there some way of getting the allocated size of the list? With Python 2.6 and newer you can use sys.getsizeof() t

Re: List size versus list allocation

2010-05-02 Thread Peter Otten
Steven D'Aprano wrote: > Python lists are over-allocated: whenever they need to be resized, they > are made a little bit larger than necessary so that appends will be fast. > > See: > > http://code.python.org/hg/trunk/file/e9d930f8b8ff/Objects/listobject.c > > I'm interested in gathering some s

List size versus list allocation

2010-05-02 Thread Steven D'Aprano
Python lists are over-allocated: whenever they need to be resized, they are made a little bit larger than necessary so that appends will be fast. See: http://code.python.org/hg/trunk/file/e9d930f8b8ff/Objects/listobject.c I'm interested in gathering some statistics on this, and to do so I need