[Python-checkins] r46181 - python/branches/rjones-prealloc

Jim Jewett jimjjewett at gmail.com
Thu May 25 00:24:56 CEST 2006


On 5/24/06, richard.jones <python-checkins at python.org> wrote:
> Author: richard.jones
> Date: Wed May 24 17:10:50 2006
> New Revision: 46181
>
> Removed:
>    python/branches/rjones-prealloc/
> Log:
> Didn't pan out - at best we can speed up appends by about 7-8% for lists of
> 50-100 elements. For the large part the benefit is 0-2%. For lists under 20
> elements, peformance is actually reduced when pre-allocating.

Is this because you don't know (often enough) what size to allocate?
Or are you actually saying that even if you know exactly how long the
list will be, it is better to grow and copy than to allocate it all at
once?

For instance,

    d=dict()
    t=tuple()

    ...

   k=d.keys()
   l=list(t)

Don't benefit?

-jJ


More information about the Python-checkins mailing list