cpython
cpython copied to clipboard
gh-142863: optimize list and set calls with generator expressions
- Issue: gh-142863
Benchmark results:
Before:
❯ ./python.exe -m timeit "list(x for x in range(10000))"
2000 loops, best of 5: 188 usec per loop
❯ ./python.exe -m timeit "set(x for x in range(10000))"
1000 loops, best of 5: 226 usec per loop
After:
❯ ./python.exe -m timeit "list(x for x in range(10000))"
2000 loops, best of 5: 150 usec per loop
❯ ./python.exe -m timeit "set(x for x in range(10000))"
2000 loops, best of 5: 178 usec per loop
This looks promising.
@kumaraditya303 can you benchmark this with small sequences, as those tend to more common.
@iritkatriel could you take a look, as author of the tuple/any/all optimization.
can you benchmark this with small sequences, as those tend to more common.
Benchmark with smaller sequence: Before:
❯ ./python.exe -m timeit "list(x for x in range(25))"
500000 loops, best of 5: 483 nsec per loop
After:
❯ ./python.exe -m timeit "list(x for x in range(25))"
500000 loops, best of 5: 390 nsec per loop
@markshannon I have fixed the merge conflicts, can you review this?