mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
Merge pull request #7562 from drinkcat/seq-perf-1
seq: Directly write separator string, instead of using format
This commit is contained in:
commit
36231f7551
2 changed files with 16 additions and 2 deletions
|
@ -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
|
by about 2 times for a floating point increment test case, leading to similar
|
||||||
performance compared with GNU `seq`.
|
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
|
[0]: https://github.com/sharkdp/hyperfine
|
||||||
|
|
|
@ -260,7 +260,7 @@ fn print_seq(
|
||||||
let mut is_first_iteration = true;
|
let mut is_first_iteration = true;
|
||||||
while !done_printing(&value, &increment, &last) {
|
while !done_printing(&value, &increment, &last) {
|
||||||
if !is_first_iteration {
|
if !is_first_iteration {
|
||||||
write!(stdout, "{separator}")?;
|
stdout.write_all(separator.as_bytes())?;
|
||||||
}
|
}
|
||||||
format.fmt(&mut stdout, &value)?;
|
format.fmt(&mut stdout, &value)?;
|
||||||
// TODO Implement augmenting addition.
|
// TODO Implement augmenting addition.
|
||||||
|
@ -268,7 +268,7 @@ fn print_seq(
|
||||||
is_first_iteration = false;
|
is_first_iteration = false;
|
||||||
}
|
}
|
||||||
if !is_first_iteration {
|
if !is_first_iteration {
|
||||||
write!(stdout, "{terminator}")?;
|
stdout.write_all(terminator.as_bytes())?;
|
||||||
}
|
}
|
||||||
stdout.flush()?;
|
stdout.flush()?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue