[issue36551] Optimize list comprehensions with preallocate size and protect against overflow

anthony shaw report at bugs.python.org
Mon Apr 8 07:47:48 EDT 2019


anthony shaw <anthony.p.shaw at gmail.com> added the comment:

> This patch makes it slow for small iterators

That is a one-off cost for the __length_hint__ of the range object specifically.
Objects with a known length (lists, sets, tuples) would not have that overhead.

I can run a more useful set of benchmarks against this.

So the +0.6us would be the same for ranges 8-16. Then less for 16-25, then again for 25-35 as the removal of the reallocation process has a more significant factor for larger ranges.

----------
nosy:  -pablogsal

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36551>
_______________________________________


More information about the Python-bugs-list mailing list