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

sorted() *does* convert its input to a list first, and only then sorts it. It 
calls PySequence_List() for that, which in turn uses list_extend(), which then 
applies the obvious optimisation of copying input lists (and tuples) directly.

What you are seeing here is probably mostly this difference:

$ python3.7 -m timeit 'list(i for i in range(100))'
50000 loops, best of 5: 5.95 usec per loop
$ python3.7 -m timeit '[i for i in range(100)]'
100000 loops, best of 5: 3.26 usec per loop

----------
components: +Interpreter Core
nosy: +scoder
type:  -> performance
versions: +Python 3.8 -Python 3.6

_______________________________________
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