Skip to content

Conversation

@drinkcat
Copy link
Collaborator

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

@github-actions
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

@drinkcat
Copy link
Collaborator 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
Collaborator 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 :)

@github-actions
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.
@github-actions
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