Python 2.0b1 List comprehensions are slow
Alex Martelli
aleaxit at yahoo.com
Tue Sep 12 16:53:07 EDT 2000
"Guido van Rossum" <guido at beopen.com> wrote in message
news:cppum9bf62.fsf at cj20424-a.reston1.va.home.com...
[snip]
> - Preallocate the result list so that the append() can be faster.
...but not at the cost of breaking the equivalence with 'for',
please...? I wouldn't want my sequence-objects to have to
implement 'length' to be usable in comprehensions, when
they don't have to in order to be usable in 'for' (in fact, I
really like the idea of my sequence-objects being 'lazy'...!).
Maybe a performance-hint to the result-list "I'm probably
about to append a lot of things" (and a closing "I'm done
appending now, trim if need be") might help the list know
not to allocate too-small slices of space at a time...? (This
could make append's cost amortized-linear rather than
quadratic, at some temporary cost in memory use, by
having the list switch to a geometric progression of
growth rather than a linear one...).
Alex
More information about the Python-list
mailing list