This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author scoder
Recipients Antony.Lee, scoder
Date 2018-02-25.09:54:31
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1519552472.31.0.467229070634.issue32945@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-02-25 09:54:32scodersetrecipients: + scoder, Antony.Lee
2018-02-25 09:54:32scodersetmessageid: <1519552472.31.0.467229070634.issue32945@psf.upfronthosting.co.za>
2018-02-25 09:54:32scoderlinkissue32945 messages
2018-02-25 09:54:31scodercreate