Avoid string-to-byte conversion

Do not create byte slices from a fixed string repeatedly. Instead, perform theconversion once and capture the result.

BadGood
  1. for i := 0; i < b.N; i++ {
  2. w.Write([]byte("Hello world"))
  3. }
  1. data := []byte("Hello world")
  2. for i := 0; i < b.N; i++ {
  3. w.Write(data)
  4. }
  1. BenchmarkBad-4 50000000 22.2 ns/op
  1. BenchmarkGood-4 500000000 3.25 ns/op