I'm wondering what the fastest way would be to create a string of n
instances of the same character. I could imagine a few approaches, some naive and some less so:
String concatenation (very naive)
func nchars(b byte, n int) string {
s := ""
c := string([]byte{b})
for i := 0; i < n; i++ {
s += c
}
return s
}
Byte slice
func nchars(b byte, n int) string {
s := make([]byte, n)
for i := 0; i < n; i++ {
s[i] = b
}
return string(s)
}