Skip to content

seq: Buffer writes to stdout #7485

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

Merged
merged 1 commit into from
Mar 19, 2025
Merged

seq: Buffer writes to stdout #7485

merged 1 commit into from
Mar 19, 2025

Conversation

drinkcat
Copy link
Contributor

Use a BufWriter to wrap stdout: reduces the numbers of system calls, improves performance drastically (2x in some cases).

Fixes part of #7482, see this comment: #7482 (comment)

Thanks @mjguzik!

For floating point prints, we are now faster than GNU:

taskset -c 0 hyperfine -L seq seq,./seq-main,target/release/seq "{seq} 0 0.1 100000"
Benchmark 1: seq 0 0.1 100000
  Time (mean ± σ):     161.6 ms ±   0.3 ms    [User: 160.8 ms, System: 0.6 ms]
  Range (min … max):   161.2 ms … 162.4 ms    18 runs
 
Benchmark 2: ./seq-main 0 0.1 100000
  Time (mean ± σ):     282.7 ms ±   5.0 ms    [User: 221.0 ms, System: 60.0 ms]
  Range (min … max):   279.7 ms … 296.2 ms    10 runs

Benchmark 3: target/release/seq 0 0.1 100000
  Time (mean ± σ):     143.8 ms ±   0.3 ms    [User: 143.0 ms, System: 0.6 ms]
  Range (min … max):   143.2 ms … 144.4 ms    20 runs
 
Summary
  target/release/seq 0 0.1 100000 ran
    1.12 ± 0.00 times faster than seq 0 0.1 100000
    1.97 ± 0.03 times faster than ./seq-main 0 0.1 100000

Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/timeout/timeout (passes in this run but fails in the 'main' branch)

@sylvestre
Copy link
Contributor

please add this bench in https://github.com/uutils/coreutils/blob/main/src/uu/seq/BENCHMARKING.md
thanks

@drinkcat
Copy link
Contributor Author

please add this bench in https://github.com/uutils/coreutils/blob/main/src/uu/seq/BENCHMARKING.md thanks

Sure, done. I also stole some of the content I had written for #7458 (will rebase that MR on top of this one, I assume this one will be merged first).

by about 2 times for a floating point increment test case, leading to similar
performance compared with GNU `seq`:
```shell
taskset -c 0 hyperfine -L seq seq,./seq-main,target/release/seq "{seq} 0 0.1 100000"
Copy link
Contributor

Choose a reason for hiding this comment

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

i don't think we need to document the results
just the commands

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Dropped.

I saw some results in some other BENCHMARKING.md so I just put them there... Might be nice to codify what's expected in those documentation files (maybe in CONTRIBUTING.md?). Not a big deal.

Copy link
Contributor

Choose a reason for hiding this comment

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

sure, don't hesitate to make a proposition :)

Copy link

GNU testsuite comparison:

GNU test failed: timeout/timeout.log. timeout/timeout.log is passing on 'main'. Maybe you have to rebase?
Congrats! The gnu test misc/stdbuf.log is no longer failing!

Use a BufWriter to wrap stdout: reduces the numbers of system calls,
improves performance drastically (2x in some cases).

Also document use cases in src/uu/seq/BENCHMARKING.md, and the
optimization we have just done here.
Copy link

GNU testsuite comparison:

Congrats! The gnu test timeout/timeout.log is no longer failing!

@sylvestre sylvestre merged commit 09f4e60 into uutils:main Mar 19, 2025
68 checks passed
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.

2 participants