Stefan Behnel <stefan...@behnel.de> added the comment:

The constant function call overhead doesn't make a big difference:

$ /opt/python3.7-opt/bin/python3 -m timeit 'list(i for i in range(1000))'
5000 loops, best of 5: 55 usec per loop
$ /opt/python3.7-opt/bin/python3 -m timeit '[i for i in range(1000)]'
10000 loops, best of 5: 30.7 usec per loop

The difference is that comprehensions are generally more efficient than 
generators, simply because they are more specialised. When a generator is 
created, it does not know whether it will be passed into list() to quickly 
unpack it into a list, or into some complex machinery that just requests one 
value per year, or only one value at all and then throws it away.

I searched a bit, but couldn't find a ticket about the performance difference 
above, although I'm sure there must be one. So I'll leave this open for now, 
assuming that there might still be something to improve here.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue32945>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to