News for hackers. Stuff that matters.
Re:How is GNU `yes` so fast? by masklinn on Tuesday June 13, 2017 @07:01AM (#14543950)
According to the article/experiment you don't have to bork up the code much, just copy your stuff into a big buffer before you start printing it (and print using write(2) instead of puts)
Re:How is GNU `yes` so fast? by microtherion on Tuesday June 13, 2017 @07:26AM (#14544026)
This works easily for the default case, which prints "y\n" (two bytes), which is likely to divide BUFSIZ. To handle the general case with the same efficiency, you have to have a buffer size that is a multiple of both BUFSIZ and the length of the string to be printed. It appears that GNU yes will not do that and simply does unaligned writes in this case, which is likely to be considerably slower (possibly slower than write would have been).
Re:How is GNU `yes` so fast? by masklinn on Tuesday June 13, 2017 @08:08AM (#14544175)
> It appears that GNU yes will not do that and simply does unaligned writes in this case, which is likely to be considerably slower (possibly slower than write would have been).

Why would it be slower to do a single, say, 8190 bytes write instead of 2730 3-byte writes?

Re:How is GNU `yes` so fast? by AstralStorm on Tuesday June 13, 2017 @10:46AM (#14545098)
Generally writes not aligned to cache line are slightly slower on most common architectures, vastly slower on others. (Such as many MIPS)

Small write calls themselves incur a considerable syscall overhead.