Also very simple FreeBSD implementation [1] is not too slow on my 10-years old notebook:
> time yes test_string | dd of=/dev/null bs=1M count=65536
...
2646329200 bytes transferred in 1.709196 secs (1548288918 bytes/sec)
0.023u 0.850s 0:01.71 50.8% 5+166k 0+0io 0pf+0w
Firefox probably have used more CPU time while I was composing this comment - thanks to JS (in other tabs, HN is a rare example of a site which doesn't abuse my CPU). FF is almost always on the 1st line in top.If you'll check top/powertop and a typical desktop or a server you'll likely find better targets than 'yes' to reduce energy use.
[1] https://github.com/freebsd/freebsd-src/blob/main/usr.bin/yes...
While in general efficient programs can save energy, the "saved" MB/s do not necessarily correlate with saved J. There is no direct cost for a instruction, there is a severe overhead from the machine plainly being switched on. And it's not like you will always be able to "use" that saved MB/s for something else.
And you entirely neglect the "cost" of optimizing. Alone the time spent looking at inefficient code probably cost more energy than all the actually saved energy by a single change.
Consider the time someone could have spent on something else, with significantly more impact.
About the second part of your comment, it's true that optimizing has a cost, and if I were creating a "yes" or "cat" program for personal use it would obviously be pointless to optimize. But if it's a program ran by millions of people often (probably more true of "cat" than "yes"), it's not that obvious to me that millions of little savings cannot offset the time of one person optimizing.