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 Stefan Pochmann
Recipients Stefan Pochmann
Date 2020-02-01.21:42:08
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1580593329.06.0.491648028148.issue39521@roundup.psfhosted.org>
In-reply-to
Content
Somehow `reversed` became much slower than `iter` on lists:

List with 1,000 elements:

> python -m timeit -s "a = list(range(1000))" "list(iter(a))"
50000 loops, best of 5: 5.73 usec per loop

> python -m timeit -s "a = list(range(1000))" "list(reversed(a))"
20000 loops, best of 5: 14.2 usec per loop

List with 1,000,000 elements:

> python -m timeit -s "a = list(range(250)) * 4000" "list(iter(a))"
50 loops, best of 5: 7.08 msec per loop

> python -m timeit -s "a = list(range(250)) * 4000" "list(reversed(a))"
20 loops, best of 5: 15.5 msec per loop

On another machine I tried ten different Python versions and found out it's only version 3.8.1 and only the 32-bit version:

                32-bit              64-bit
CPython     iter   reversed     iter   reversed
 3.5.4      19.8     19.9       22.4     22.7
 3.6.8      19.8     19.9       22.3     22.6
 3.7.6      19.9     19.9       22.3     22.5
 3.8.1      19.8     24.9       22.4     22.6

Another time with 3.8.0 instead of 3.8.1:

                32-bit              64-bit
CPython     iter   reversed     iter   reversed
 3.5.4      19.5     19.6       21.9     22.2
 3.6.8      19.5     19.7       21.8     22.1
 3.7.6      19.5     19.6       21.7     22.0
 3.8.0      19.4     24.5       21.7     22.1

I used the "Stable Releases" "executable installer"s from here:
https://www.python.org/downloads/windows/

More details here: https://stackoverflow.com/q/60005302/12671057
History
Date User Action Args
2020-02-01 21:42:09Stefan Pochmannsetrecipients: + Stefan Pochmann
2020-02-01 21:42:09Stefan Pochmannsetmessageid: <1580593329.06.0.491648028148.issue39521@roundup.psfhosted.org>
2020-02-01 21:42:09Stefan Pochmannlinkissue39521 messages
2020-02-01 21:42:08Stefan Pochmanncreate