|
|
|
|
|
by ninkendo
850 days ago
|
|
It's a dumb tradeoff, IMO. The job of `yes` is to produce output only when it's being read, and this implementation copies the "y\n" until it fills up a BUFSIZ-sized buffer (8KB on my system), then outputs that buffer until the write fails. This means you're paying the cost to fill the buffer even if you're only reading one line (which is a common use case for "yes": Responding with "y" to software that is asking you for confirmation, which generally only reads input once.) Which means "yes" will always occupy at least 8kb of RAM even thought it doesn't need to, and you're spending thousands of CPU cycles copying into a buffer even though you don't need to. 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.) |
|