Uh oh!
There was an error while loading. Please reload this page.
GH-91432: Add more FOR_ITER specializations - #94096
Closed
sweeneyde wants to merge 5 commits into
Closed
Conversation
sweeneyde
commented
Jun 21, 2022
MemberAuthor
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) |
Member
Before adding any more specializations for builtin iterators, I'd like to try implementing faster-cpython/ideas#392 and add specialization for generators. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
#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.