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 pablogsal
Recipients Aaron Hall, anthony shaw, methane, ncoghlan, pablogsal, ronaldoussoren, serhiy.storchaka
Date 2019-04-08.13:09:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1554728973.18.0.881619811769.issue36551@roundup.psfhosted.org>
In-reply-to
Content
> 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: 945 ns +- 27 ns


PR 12718:
❯ ./python.exe ../check.py -n 10
.....................
list_comp: Mean +- std dev: 1.33 us +- 0.05 us
History
Date User Action Args
2019-04-08 13:09:33pablogsalsetrecipients: + pablogsal, ronaldoussoren, ncoghlan, methane, serhiy.storchaka, Aaron Hall, anthony shaw
2019-04-08 13:09:33pablogsalsetmessageid: <1554728973.18.0.881619811769.issue36551@roundup.psfhosted.org>
2019-04-08 13:09:33pablogsallinkissue36551 messages
2019-04-08 13:09:32pablogsalcreate