News for hackers. Stuff that matters.
Re:A Little Story About the `yes` Unix Command by Y_Y on Thursday October 12, 2017 @04:54AM (#15456593)
Forgive me if I'm missing something subtle, but aren't the first two examples Useless Use Of Cat?
Re:A Little Story About the `yes` Unix Command by jwilk on Thursday October 12, 2017 @05:10AM (#15456661)
No, the use of cat is intentional.

The output of yes(1) is normally consumed by another program, not redirected to a file, so this is what the examples emulate.

Re:A Little Story About the `yes` Unix Command by isatty on Thursday October 12, 2017 @04:58AM (#15456609)
Yes they are. Why not just send it straight to /dev/null?
Re:A Little Story About the `yes` Unix Command by wahern on Thursday October 12, 2017 @12:59PM (#15459405)
1) Because splice(2) requires either the source or sink to be a pipe. The source is a regular file so the sink has to be a pipe.

2) Because the example Rust program(s), emulating yes(1), had no [simple] way to measure throughput except by piping to another program. We can't fairly compare program A that writes directly to /dev/null with program B that writes to a pipe even if program A can measure its throughput.

2a) What jwilk said.

3) For some reason I thought that glibc had optimizations to elide fwrites to /dev/null, and some of my code was using stdio (e.g. for the final trailing bytes less than the pagesize). I could've sworn either glibc or bash did this, but I can't find any mention of it, now. I realize it would be crazy difficult and ugly for glibc to do this (because of dup2, etc), but glibc does alot of crazy things, and in any event I didn't bother checking beforehand.

Mostly it comes down to fairly comparing benchmarks and kernel facilities. Otherwise, yes, those would be classic examples of Useless Use of Cat.