The code:
package concat
import (
"testing"
)
var s33 = []byte{32: 'b'}
var a = string(s33)
func Benchmark_e_33(b *testing.B) {
for i := 0; i < b.N; i++ {
_ = a + a // a + a does not escape
}
}
"go test -gcflags=-m" shows: a + a does not escape
but "go test -bench=. -benchmem" shows:
Benchmark_e_33-4 16544446 68.35 ns/op 80 B/op 1 allocs/op
In my impression, memory blocks allocated on stack are not counted in the bench result.