Hacker News new | ask | show | jobs
by forgotpwd16 390 days ago
Replace `write(..)` with `puts("y")` and you'll be an order of magnitude faster. This is due to `puts` (`printf` too) being buffered (data isn't written to term/file immediately but retained in memory until some point). Improving this process (as seen in the reddit thread) gets GNU-yes.
2 comments

It's line buffered when it prints to terminal.
One rarely needs yes' output to be a terminal.
Don't you actively want it to flush asap since you're usually piping into another program?

I suspect what you suggest creates a more voluminous dump but is slower in the desired use case