-
-
Notifications
You must be signed in to change notification settings - Fork 833
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
Add buffering to stdout when it's not a terminal. #885
Conversation
Thank you for bringing this up to date! It would be good to see some benchmark results ( |
By the way, you could add
to the commit message to attribute it to both you and the original author. |
I tried running the the rust-lang repository and got:
|
Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
---|---|---|---|---|
./fd-master --hidden --no-ignore '' '/home/thayne/bulk-home/devel/rust-lang' |
245.2 ± 2.7 | 241.6 | 249.7 | 1.00 |
./fd-feature --hidden --no-ignore '' '/home/thayne/bulk-home/devel/rust-lang' |
269.5 ± 4.4 | 263.3 | 278.1 | 1.10 ± 0.02 |
Simple pattern
Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
---|---|---|---|---|
./fd-master '.*[0-9]\.jpg$' '/home/thayne/bulk-home/devel/rust-lang' |
343.1 ± 4.6 | 338.4 | 355.0 | 1.00 ± 0.01 |
./fd-feature '.*[0-9]\.jpg$' '/home/thayne/bulk-home/devel/rust-lang' |
342.6 ± 1.8 | 340.6 | 346.4 | 1.00 |
Simple pattern (-HI)
Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
---|---|---|---|---|
./fd-master -HI '.*[0-9]\.jpg$' '/home/thayne/bulk-home/devel/rust-lang' |
242.9 ± 3.7 | 238.7 | 251.2 | 1.00 |
./fd-feature -HI '.*[0-9]\.jpg$' '/home/thayne/bulk-home/devel/rust-lang' |
248.9 ± 5.3 | 242.5 | 258.1 | 1.02 ± 0.03 |
File extension
Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
---|---|---|---|---|
./fd-master -HI --extension jpg '' '/home/thayne/bulk-home/devel/rust-lang' |
250.9 ± 4.4 | 246.0 | 258.4 | 1.00 |
./fd-feature -HI --extension jpg '' '/home/thayne/bulk-home/devel/rust-lang' |
253.3 ± 2.9 | 249.3 | 258.6 | 1.01 ± 0.02 |
File type
Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
---|---|---|---|---|
./fd-master -HI --type l '' '/home/thayne/bulk-home/devel/rust-lang' |
245.2 ± 4.6 | 240.8 | 255.7 | 1.00 |
./fd-feature -HI --type l '' '/home/thayne/bulk-home/devel/rust-lang' |
251.1 ± 4.9 | 246.5 | 261.0 | 1.02 ± 0.03 |
Cold cache
Command | Mean [s] | Min [s] | Max [s] | Relative |
---|---|---|---|---|
./fd-master -HI '.*[0-9]\.jpg$' '/home/thayne/bulk-home/devel/rust-lang' |
28.951 ± 0.725 | 28.224 | 29.674 | 1.01 ± 0.03 |
./fd-feature -HI '.*[0-9]\.jpg$' '/home/thayne/bulk-home/devel/rust-lang' |
28.654 ± 0.318 | 28.339 | 28.975 | 1.00 |
interestingly, it looks like this branch is actually a little bit slower, I'm not really sure why.
I switch back to using
|
Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
---|---|---|---|---|
./fd-master --hidden --no-ignore '' '/home/thayne/bulk-home/devel/rust-lang' |
250.0 ± 2.4 | 245.9 | 253.7 | 1.00 |
./fd-feature --hidden --no-ignore '' '/home/thayne/bulk-home/devel/rust-lang' |
254.4 ± 1.4 | 251.7 | 255.9 | 1.02 ± 0.01 |
Simple pattern
Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
---|---|---|---|---|
./fd-master '.*[0-9]\.jpg$' '/home/thayne/bulk-home/devel/rust-lang' |
342.2 ± 3.1 | 336.3 | 347.9 | 1.00 |
./fd-feature '.*[0-9]\.jpg$' '/home/thayne/bulk-home/devel/rust-lang' |
342.7 ± 2.7 | 340.3 | 349.0 | 1.00 ± 0.01 |
Simple pattern (-HI)
Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
---|---|---|---|---|
./fd-master -HI '.*[0-9]\.jpg$' '/home/thayne/bulk-home/devel/rust-lang' |
242.6 ± 3.1 | 239.2 | 249.0 | 1.00 |
./fd-feature -HI '.*[0-9]\.jpg$' '/home/thayne/bulk-home/devel/rust-lang' |
244.9 ± 3.8 | 239.2 | 253.7 | 1.01 ± 0.02 |
File extension
Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
---|---|---|---|---|
./fd-master -HI --extension jpg '' '/home/thayne/bulk-home/devel/rust-lang' |
253.8 ± 3.0 | 249.2 | 259.3 | 1.00 |
./fd-feature -HI --extension jpg '' '/home/thayne/bulk-home/devel/rust-lang' |
254.7 ± 3.2 | 250.6 | 260.4 | 1.00 ± 0.02 |
File type
Command | Mean [ms] | Min [ms] | Max [ms] | Relative |
---|---|---|---|---|
./fd-master -HI --type l '' '/home/thayne/bulk-home/devel/rust-lang' |
243.4 ± 4.5 | 238.9 | 255.0 | 1.00 |
./fd-feature -HI --type l '' '/home/thayne/bulk-home/devel/rust-lang' |
244.8 ± 3.0 | 240.9 | 249.1 | 1.01 ± 0.02 |
Cold cache
Command | Mean [s] | Min [s] | Max [s] | Relative |
---|---|---|---|---|
./fd-master -HI '.*[0-9]\.jpg$' '/home/thayne/bulk-home/devel/rust-lang' |
29.176 ± 0.388 | 28.729 | 29.432 | 1.00 ± 0.02 |
./fd-feature -HI '.*[0-9]\.jpg$' '/home/thayne/bulk-home/devel/rust-lang' |
29.120 ± 0.375 | 28.754 | 29.504 | 1.00 |
Ok, thank you. And do we have a significant improvement for searches that need to write a lot of results to stdout? Something like |
Have you played around with different buffer sizes? https://doc.rust-lang.org/stable/std/io/struct.BufWriter.html#method.with_capacity |
I have not I'm wondering if it might be that the bottleneck, at least on my system, is reading from disk, so even if it writes to stdout faster, it doesn't impact the overall run time. So I tried changing it to write the output to a file, instead of whatever hyperfine does with the output by default, and got much better results:
|
This is based on the work of sharkdp#736 by @sourlemon207. I've added the suggestion I recommended on that PR.
Co-authored-by: sourlemon207 <jw1756@protonmail.com>
Using hyperfine, it should write to |
I ran some benchmarks myself. I see quite significant improvements when a lot of results (1.6 million) are printed:
In combination with the changes by @tavianator, this will make colorized searches almost 5x faster (compared to 8.2.1) 🥳 Very cool!
|
A |
Interesting. I was secretly hoping that you would explain what's going on 😄 - thanks! So I guess this means that we would get slightly more realistic benchmarking results if we pipe the output to a file? |
I tried out various buffer sizes and it doesn't make a huge difference as long as the buffer size is larger than a few 100 B. The default is 8 KiB which seems reasonable. |
If the output goes to an actual file (on
Even more so, if we are writing to an SSD:
|
I see no reason to delay merging this. |
Depends what you're trying to be realistic about :). Writing to You might also try writing to a file, but that complicates things. Depending on how much you write, the data might only hit the page cache, or the flash cache of a hard drive, etc. The filesystem, hardware, etc. will all affect the performance and make it harder to interpret the results. The right thing to do depends on what you actually want to measure. I think mostly people care about interactive use, where writing to the TTY is probably the biggest bottleneck. The current benchmarks don't really capture this well. Another common use is probably piping |
I see no reason to delay merging this. Thank you @sourlemon207 @tmccombs @tavianator. I'll create a ticket to address the shortcomings of the current benchmark set. |
Follow-up of #736