Re:How the GNU coreutils are tested
by tomsmeding on Wednesday February 21, 2024 @06:11PM
(#39460952)
On the other hand, 8kb is just 2 virtual memory pages; overhead of running a process in the first place will be bigger than that. And the time of filling the 8kb buffer is likely not much more than the cost of a context switch to the reading process.
Except that it does not display a single yes line by default, so its primary purpose is effectively to print them forever. Also, in this particular corner of the netsphere we should applaud the maddening research for performance that people put into that seemingly obvious command
It prints them as long as the receiving process reads them. That’s how pipes work. When piping to a process that only reads from stdin once (you know, like the original purpose of the command, to respond “yes” to prompts from processes that are asking for confirmation), it will only write once (because stdout is line-buffered, so printing a string with a newline will block until something reads it.) Filling a buffer with 4,000 instances of “y\n” on the off chance that the receiving process will actually read all of those, is doing extra work that may not be needed.
“Maddening research for performance” in this case is coming at the expense of energy expenditure: you’re always allocating that memory and always filling a buffer with thousands of “y”s even when it’s just going to get thrown out. That should not be applauded. People should be just as concerned about energy usage as they are about wall clock time.
Re:How the GNU coreutils are tested
by Ferret7446 on Thursday February 22, 2024 @04:30AM
(#39464975)
You're optimizing for the wrong thing. Sure, it's "inefficient" for a single prompt, but what about when you're doing a batch operation with millions of prompts that you actually need to be fast?
That inefficiency is a far bigger sin than the "slowness" of yes needing a write() call for every line it emits, given the intended purpose of the command (which is not, as the code suggests, to saturate a unix pipe as fast as you can.)