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

Eliminate most str.format() and %-formatting #995

Merged
merged 2 commits into from Aug 10, 2022
Merged

Eliminate most str.format() and %-formatting #995

merged 2 commits into from Aug 10, 2022

Conversation

hynek
Copy link
Member

@hynek hynek commented Aug 7, 2022

Micro-optimization is the root of all success.

@hynek
Copy link
Member Author

hynek commented Aug 10, 2022

This btw gives us ~6% performance gain on class creation for simple classes, just by being more idiomatic (and getting rid of the mistake called format).

Measured using:

def create(loops):
    range_it = range(loops)
    d = attrs.define

    t0 = pyperf.perf_counter()

    for _ in range_it:
        @d
        class C:
            a: int
            b: int

    return pyperf.perf_counter() - t0

I presume that more complex classes give us even bigger gainzzz.

Copy link
Member

@Tinche Tinche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hynek hynek merged commit 6151683 into main Aug 10, 2022
@hynek hynek deleted the more-f-strings branch August 10, 2022 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants