Message402649
I did more benchmarks on my Windows laptop, and it seems the difference goes away after using PGO.
The benchmarking program:
#################################
from pyperf import Runner
runner = Runner()
for n in [10, 100, 1000, 10_000, 100_000]:
runner.timeit(f"for i in range({n}): pass",
stmt=f"for i in range({n}): pass")
runner.timeit(f"for i in it_{n}: pass",
setup=f"it = iter(range({n}))",
stmt="for i in it: pass")
runner.timeit(f"deque(it_{n})",
setup=(f"from collections import deque; "
f"it = iter(range({n}))"),
stmt="deque(it, maxlen=0)")
runner.timeit(f"list(iter(range({n})))",
stmt=f"list(iter(range({n})))")
###################################
The results (without PGO):
PS C:\Users\sween\Source\Repos\cpython2\cpython> .\python.bat -m pyperf compare_to .\20e3149c175a24466c7d1c352f8ff2c11effc489.json .\cffa90a8b0057d7e7456571045f2fb7b9ceb426f.json -G
Running Release|x64 interpreter...
Slower (15):
- list(iter(range(100))): 741 ns +- 13 ns -> 836 ns +- 11 ns: 1.13x slower
- for i in range(100000): pass: 2.05 ms +- 0.05 ms -> 2.26 ms +- 0.06 ms: 1.10x slower
- list(iter(range(1000))): 12.2 us +- 0.1 us -> 13.2 us +- 0.2 us: 1.08x slower
- for i in range(10000): pass: 203 us +- 4 us -> 219 us +- 4 us: 1.08x slower
- for i in range(100): pass: 1.18 us +- 0.02 us -> 1.27 us +- 0.03 us: 1.08x slower
- for i in range(1000): pass: 18.1 us +- 0.3 us -> 19.5 us +- 0.3 us: 1.07x slower
- list(iter(range(10000))): 145 us +- 7 us -> 152 us +- 2 us: 1.05x slower
- list(iter(range(100000))): 1.98 ms +- 0.06 ms -> 2.06 ms +- 0.05 ms: 1.04x slower
- for i in range(10): pass: 265 ns +- 9 ns -> 272 ns +- 8 ns: 1.03x slower
- deque(it_1000): 324 ns +- 4 ns -> 332 ns +- 8 ns: 1.02x slower
- deque(it_100000): 327 ns +- 5 ns -> 333 ns +- 7 ns: 1.02x slower
- list(iter(range(10))): 357 ns +- 7 ns -> 363 ns +- 3 ns: 1.02x slower
- deque(it_10): 325 ns +- 5 ns -> 330 ns +- 5 ns: 1.01x slower
- deque(it_100): 325 ns +- 6 ns -> 329 ns +- 4 ns: 1.01x slower
- deque(it_10000): 326 ns +- 7 ns -> 330 ns +- 4 ns: 1.01x slower
Faster (2):
- for i in it_10: pass: 26.0 ns +- 1.4 ns -> 25.3 ns +- 0.3 ns: 1.03x faster
- for i in it_1000: pass: 25.7 ns +- 0.7 ns -> 25.3 ns +- 0.4 ns: 1.02x faster
Benchmark hidden because not significant (3): for i in it_100: pass, for i in it_10000: pass, for i in it_100000: pass
Geometric mean: 1.03x slower
###################################
The results (with PGO):
PS C:\Users\sween\Source\Repos\cpython2\cpython> .\python.bat -m pyperf compare_to .\PGO-20e3149c175a24466c7d1c352f8ff2c11effc489.json .\PGO-cffa90a8b0057d7e7456571045f2fb7b9ceb426f.json -G
Running PGUpdate|x64 interpreter...
Slower (7):
- for i in it_100: pass: 20.3 ns +- 0.5 ns -> 21.3 ns +- 0.7 ns: 1.05x slower
- for i in it_10000: pass: 20.4 ns +- 0.6 ns -> 21.4 ns +- 0.8 ns: 1.05x slower
- for i in it_100000: pass: 20.5 ns +- 0.5 ns -> 21.4 ns +- 0.6 ns: 1.05x slower
- for i in it_1000: pass: 20.3 ns +- 0.5 ns -> 21.2 ns +- 0.5 ns: 1.05x slower
- for i in it_10: pass: 20.3 ns +- 0.5 ns -> 21.1 ns +- 0.5 ns: 1.04x slower
- for i in range(10): pass: 214 ns +- 3 ns -> 219 ns +- 11 ns: 1.03x slower
- deque(it_100000): 288 ns +- 5 ns -> 291 ns +- 12 ns: 1.01x slower
Faster (7):
- list(iter(range(10000))): 112 us +- 3 us -> 96.4 us +- 3.4 us: 1.16x faster
- list(iter(range(1000))): 9.69 us +- 0.15 us -> 8.39 us +- 0.26 us: 1.15x faster
- list(iter(range(100000))): 1.65 ms +- 0.04 ms -> 1.48 ms +- 0.04 ms: 1.11x faster
- list(iter(range(100))): 663 ns +- 11 ns -> 623 ns +- 12 ns: 1.06x faster
- for i in range(1000): pass: 14.6 us +- 0.5 us -> 14.2 us +- 0.3 us: 1.03x faster
- for i in range(10000): pass: 162 us +- 2 us -> 159 us +- 3 us: 1.02x faster
- for i in range(100000): pass: 1.64 ms +- 0.03 ms -> 1.62 ms +- 0.04 ms: 1.01x faster
Benchmark hidden because not significant (6): deque(it_10), list(iter(range(10))), for i in range(100): pass, deque(it_100), deque(it_1000), deque(it_10000)
Geometric mean: 1.01x faster |
|
Date |
User |
Action |
Args |
2021-09-25 21:32:28 | Dennis Sweeney | set | recipients:
+ Dennis Sweeney, gvanrossum, rhettinger, lukasz.langa, serhiy.storchaka |
2021-09-25 21:32:28 | Dennis Sweeney | set | messageid: <1632605548.19.0.808696312694.issue45026@roundup.psfhosted.org> |
2021-09-25 21:32:28 | Dennis Sweeney | link | issue45026 messages |
2021-09-25 21:32:28 | Dennis Sweeney | create | |
|