Pablo Galindo Salgado <pablog...@gmail.com> added the comment: > 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.
That seems incorrect. This is not unique of range objects as it affects also objects with known lengths (like a list): import perf runner = perf.Runner() runner.timeit("list_comp", stmt="[x*2 for x in k]", setup="k=list(range(10))") Current master: ❯ ./python.exe ../check.py -n 10 ..................... list_comp: Mean +- std dev: 3.82 us +- 0.13 us PR 12718: ❯ ./python.exe ../check.py -n 10 ..................... list_comp: Mean +- std dev: 4.38 us +- 0.16 us Check also my other benchmark with a list iterator ( iter(list(range(10))) ) or this one with a generator comp: import perf runner = perf.Runner() runner.timeit("list_comp", stmt="[x*2 for x in it]", setup="k=list(range(10));it=(x for x in k)") Current master: ❯ ./python.exe ../check.py -n 10 ..................... list_comp: Mean +- std dev: 967 ns +- 27 ns PR 12718: ❯ ./python.exe ../check.py -n 10 ..................... list_comp: Mean +- std dev: 1.22 us +- 0.04 us ---------- nosy: +pablogsal _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue36551> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com