Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
GH-91432: Add more FOR_ITER specializations#94096
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Uh oh!
There was an error while loading. Please reload this page.
Conversation
sweeneyde commented Jun 21, 2022
In microbenchmarks, it seems adding these extra opcodes bumped some things around and made But dict items, enumerate, and tuple did speed up, as expected. microbenchmark scriptfrompyperfimportRunner, perf_counterfromitertoolsimportrepeatdeffor_range(loops, length): repetitions=repeat(None, loops) R=range(length) t0=perf_counter() for_inrepetitions: forxinR: passt1=perf_counter() returnt1-t0deffor_list(loops, length): repetitions=repeat(None, loops) L=list(map(float, range(length))) t0=perf_counter() for_inrepetitions: forxinL: passt1=perf_counter() returnt1-t0deffor_tuple(loops, length): repetitions=repeat(None, loops) T=tuple(map(float, range(length))) t0=perf_counter() for_inrepetitions: forxinT: passt1=perf_counter() returnt1-t0deffor_dict(loops, length): repetitions=repeat(None, loops) D=dict.fromkeys(map(float, range(length))) t0=perf_counter() for_inrepetitions: forx, yinD.items(): passt1=perf_counter() returnt1-t0deffor_enumerate(loops, length): repetitions=repeat(None, loops) L= [None] *lengtht0=perf_counter() for_inrepetitions: fori, xinenumerate(L): passt1=perf_counter() returnt1-t0deffor_map(loops, length): repetitions=repeat(None, loops) L= [()] *lengtht0=perf_counter() for_inrepetitions: forxinmap(len, L): passt1=perf_counter() returnt1-t0deffor_string(loops, length): repetitions=repeat(None, loops) S="a"*lengtht0=perf_counter() for_inrepetitions: forxinS: passt1=perf_counter() returnt1-t0deffor_set(loops, length): repetitions=repeat(None, loops) S={f"a{i}"foriinrange(length)} t0=perf_counter() for_inrepetitions: forxinS: passt1=perf_counter() returnt1-t0bench=Runner().bench_time_funcfornin [20, 200, 2_000, 20_000]: bench(f"for_range {n:_}", for_range, n, inner_loops=n) bench(f"for_list {n:_}", for_list, n, inner_loops=n) bench(f"for_tuple {n:_}", for_tuple, n, inner_loops=n) bench(f"for_dict {n:_}", for_dict, n, inner_loops=n) bench(f"for_enumerate {n:_}", for_enumerate, n, inner_loops=n) bench(f"for_map {n:_}", for_map, n, inner_loops=n) bench(f"for_string {n:_}", for_string, n, inner_loops=n) bench(f"for_set {n:_}", for_set, n, inner_loops=n) |
markshannon commented Jun 22, 2022 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
Before adding any more specializations for builtin iterators, I'd like to try implementing faster-cpython/ideas#392 and add specialization for generators. |
#91432
This does:
FOR_ITER(tuple)FOR_ITER(dict_items) + UNPACK_SEQUENCE(2)FOR_ITER(enumerate) + UNPACK_SEQUENCE(2) + STORE_FASTPyLongObjectI'm not sure whether all of these are worth it, but I want to see how this moves stats and micro- and macro- benchmarks.