3 ms·
But doesn't this make the typical use case (just a few "yes"s needed) slower, since first it has to fill a buffer? I would write() the buffer each time it gets
by ars 9y ago
But doesn't this make the typical use case (just a few "yes"s needed) slower, since first it has to fill a buffer?
I would write() the buffer each time it gets enlarged, in order to improve startup speed.
Also: The reddit program has a bug if the size of the buffer is not a multiple of the input text size.
And it's increasing the buffer by incrementing one at a time, instead of copying the buffer to itself, reducing the number of loops needed (at cost of slightly more complicated math).
- nostrademons 9y agoIf your only overhead is filling an 8K buffer, I don't think your user is going to care. Taking one microsecond instead of one nanosecond doesn't matter all that much when you're going to lose way more than that in pipes, the kernel, the program you're piping it to, etc.
- statictype 9y agoBut what's the use case for a large volume of continuous output? It feels like we're optimizing for the wrong use case
- pmontra 9y agoMaybe filling a disk or flooding a network connection as in yes | ssh server "cat > /dev/null" But yes take arguments so there might be more use cases: $ man yes NAME yes - output a string repeatedly until killed SYNOPSIS yes [STRING]... yes OPTION DESCRIPTION Repeatedly output a line with all specified STRING(s), or 'y'.
- coldtea 9y ago>But doesn't this make the typical use case (just a few "yes"s needed) slower, since first it has to fill a buffer? If "only few yes's are needed" then the slowdown to produce them will be inconsequential, whether they still fill a buffer in this case or not.
- dbaupp 9y ago> But doesn't this make the typical use case (just a few "yes"s needed) slower, since first it has to fill a buffer? One could put a write in the memcpy loop, so that first it writes one copy of the string, then two, then 4, 8 (etc.), meaning time to first byte is short, but it quickly gets up to the eventual asymptotic speed with a full buffer. ( https://www.reddit.com/r/rust/comments/4wde08/optimising_yes_any_further_ideas/d663d13/ https://www.reddit.com/r/rust/comments/4wde08/optimising_yes... )
- masklinn 9y agoYou could also have a static buffer full of yesses, it would increase the binary size by 8k, but GNU yes is already 40k on my system so...
- dbaupp 9y agoThat is mentioned elsewhere in this very thread, where it is also pointed out that that isn't a general solution (`yes` can print more than just y).
- Sean1708 9y ago> The reddit program has a bug if the size of the buffer is not a multiple of the input text size. The author appears to be aware of that: > Even with the function overheads and additional bounds checks of GNU's yes