seq: Directly write separator string, instead of using format#7562
Merged
sylvestre merged 1 commit intouutils:mainfrom Mar 24, 2025
Merged
seq: Directly write separator string, instead of using format#7562sylvestre merged 1 commit intouutils:mainfrom
sylvestre merged 1 commit intouutils:mainfrom
Conversation
Doing `stdout.write_all(separator.as_bytes())?` is quite a bit
faster than using format to do the same operation:
`write!(stdout, "{separator}")?`.
This speeds up by about 10% on simple cases.
We do the same for the terminator even though this has no measurable
performance impact.
Collaborator
Author
|
(probably a good idea to grep the rest of the repo for that pattern...) |
|
GNU testsuite comparison: |
Contributor
|
wahou, i wasn't expecting such difference |
drinkcat
commented
Mar 24, 2025
| @@ -260,15 +260,15 @@ fn print_seq( | |||
| let mut is_first_iteration = true; | |||
| while !done_printing(&value, &increment, &last) { | |||
| if !is_first_iteration { | |||
Collaborator
Author
There was a problem hiding this comment.
Oh, I also tried to move that test out of the loop. That makes no difference.
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.
Doing
stdout.write_all(separator.as_bytes())?is quite a bit faster than using format to do the same operation:write!(stdout, "{separator}")?.This speeds up by about 10% on simple cases.
We do the same for the terminator even though this has no measurable performance impact.
Integer increments (no point comparing with coreutils on that one, it's much faster):
Float increments, we were already faster than coreutils, we gain another 10%: