I am implementing Unix commands in Go as a way to learn more about Go. I have read some articles where people have implemented yes in various and gotten up to 3 gig per second transfer rates. Through trial an error I have gotten my Go implementation to around 1.5 gig per second:
package main
import (
f "fmt"
"os"
s "strings"
)
const bufsize = 1024 * 64
func main() {
atom := "y
"
if len(os.Args) > 1 {
atom = s.Join(os.Args[1:], " ") + "
"
}
buf := s.Repeat(atom, bufsize / len(atom))
for {
f.Print(buf)
}
}
Is there a lower level/faster function to print to stdout?