ericlagergren / go-coreutils

A cross-platform port of GNU's coreutils to Go
GNU General Public License v3.0
750 stars 69 forks source link

[yes] use fixed size byte array to improve perfromance #113

Open eranchetz opened 6 years ago

eranchetz commented 6 years ago

Using a fixed size byte array increases performance by x100


$ go run yes.go n | pv -r > /dev/null
[1.07MiB/s]

$ go run yes.go n | pv -r > /dev/null
[2.08GiB/s]```
ericlagergren commented 6 years ago

appreciate the PR! just btw, you're only filling the first N chars of the slice plus the appended linefeed, so you've got a bunch of 0 bytes in the middle:

https://play.golang.org/p/Jnq54Jspnp

eranchetz commented 6 years ago

The alternative is to append the EOL after the N Chars like so [121 10 0 0 0 0 0 0 0 0 0 0 .... 0] Does that make more sense?

Is this your implementation https://www.reddit.com/r/programming/comments/6gxf02/how_is_gnus_yes_so_fast_xpost_runix/dity5pj/ ? I can use that instead

eranchetz commented 6 years ago

@ericlagergren ok, I got your point, let me fix that does this make more sense? https://play.golang.org/p/JUpuypcAne

eranchetz commented 6 years ago

@ericlagergren I fixed it, and fixed some lint issues