Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/uu/seq/BENCHMARKING.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,18 @@ of system time). Simply wrapping `stdout` in a `BufWriter` increased performance
by about 2 times for a floating point increment test case, leading to similar
performance compared with GNU `seq`.

### Directly print strings

As expected, directly printing a string:
```rust
stdout.write_all(separator.as_bytes())?
```
is quite a bit faster than using format to do the same operation:
```rust
write!(stdout, "{separator}")?
```

The change above resulted in a ~10% speedup.


[0]: https://github.com/sharkdp/hyperfine
4 changes: 2 additions & 2 deletions src/uu/seq/src/seq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,15 +260,15 @@ fn print_seq(
let mut is_first_iteration = true;
while !done_printing(&value, &increment, &last) {
if !is_first_iteration {
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Oh, I also tried to move that test out of the loop. That makes no difference.

write!(stdout, "{separator}")?;
stdout.write_all(separator.as_bytes())?;
}
format.fmt(&mut stdout, &value)?;
// TODO Implement augmenting addition.
value = value + increment.clone();
is_first_iteration = false;
}
if !is_first_iteration {
write!(stdout, "{terminator}")?;
stdout.write_all(terminator.as_bytes())?;
}
stdout.flush()?;
Ok(())
Expand Down
Loading