Conversation
Using str.format is ~16% faster than the lambda
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #8535 +/- ##
=======================================
Coverage 97.67% 97.67%
=======================================
Files 107 107
Lines 33286 33288 +2
Branches 3918 3916 -2
=======================================
+ Hits 32513 32515 +2
Misses 559 559
Partials 214 214
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
Dreamsorcerer
approved these changes
Jul 25, 2024
Co-authored-by: Sam Bull <[email protected]>
Member
Author
|
thanks |
Contributor
Backport to 3.10: 💚 backport PR created✅ Backport PR branch: Backported as #8537 🤖 @patchback |
patchback bot
pushed a commit
that referenced
this pull request
Jul 25, 2024
Co-authored-by: Sam Bull <[email protected]> (cherry picked from commit 7108d64)
bdraco
added a commit
that referenced
this pull request
Jul 25, 2024
…_cookies (#8537) **This is a backport of PR #8535 as merged into master (7108d64).** <!-- Thank you for your contribution! --> ## What do these changes do? Small speed up to cookiejar Using `str.format` is ~16% faster than the lambda followup to #7944 (comment). I was hoping to use `join` there but later realized `str.format` will take `*args` ## Are there changes in behavior for the user? no ## Is it a substantial burden for the maintainers to support this? no benchmark ```python import timeit import itertools _FORMAT_PATH = "{0}/{1}".format path = "lolonglonglonglonglonglongng/path/to/a/file" print( timeit.timeit( 'itertools.accumulate(path.split("/"), _FORMAT_PATH)', globals=globals() ) ) print( timeit.timeit( 'itertools.accumulate(path.split("/"), lambda x, y: f"{x}/{y}")', globals=globals(), ) ) ``` Co-authored-by: J. Nick Koston <[email protected]>
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 free
to 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.
What do these changes do?
Small speed up to cookiejar
Using
str.formatis ~16% faster than the lambdafollowup to #7944 (comment). I was hoping to use
jointhere but later realizedstr.formatwill take*argsAre there changes in behavior for the user?
no
Is it a substantial burden for the maintainers to support this?
no
benchmark