Skip to content
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

gh-100762: Switch order of exception match in gen_close #101011

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

eendebakpt
Copy link
Contributor

@eendebakpt eendebakpt commented Jan 13, 2023

See #100762 (comment)

Benchmark (with optimizations including PGO):

generator: Mean +- std dev: [main_generator_pgo] 326 ns +- 15 ns -> [pr_generator_pgo] 317 ns +- 15 ns: 1.03x faster
list comprehension: Mean +- std dev: [main_generator_pgo] 176 ns +- 7 ns -> [pr_generator_pgo] 172 ns +- 7 ns: 1.02x faster
all: Mean +- std dev: [main_generator_pgo] 266 ns +- 4 ns -> [pr_generator_pgo] 263 ns +- 3 ns: 1.01x faster
all with comparison: Mean +- std dev: [main_generator_pgo] 572 ns +- 12 ns -> [pr_generator_pgo] 562 ns +- 16 ns: 1.02x faster

Benchmark hidden because not significant (1): generator exhaust

Geometric mean: 1.02x faster

Script:

import pyperf
runner = pyperf.Runner()

setup="""
l=[1,2]
"""

runner.timeit(name=f"generator", stmt=f"(x for x in l)", setup=setup)
runner.timeit(name=f"list comprehension", stmt=f"[x for x in l]", setup=setup)
stmt="""
for x in (_ for _ in ()):
    pass
"""
runner.timeit(name=f"generator exhaust", stmt=stmt, setup=setup)
runner.timeit(name=f"all", stmt=f"all( (x for x in l) ) ", setup=setup)
runner.timeit(name=f"all with comparison", stmt=f"all( (x==1 for x in l) ) ", setup=setup)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants