Sorry, I temporarily switch to Go 1.3. The result is constantly 0 0 1 for Go 1.15 when N > 2.
On Saturday, August 15, 2020 at 12:30:32 AM UTC-4, T L wrote: > > > package main > > import "fmt" > import "bytes" > import "testing" > > const N = 0 > var name = bytes.Repeat([]byte{'x'}, N) > var m = make(map[string]string, 10) > var s string > > func f() { > s = m[string(name)] > } > > func g() { > key := string(name) > s = m[key] > } > > func h() { > m[string(name)] = "Golang" > } > > func main() { > fmt.Println(testing.AllocsPerRun(1, f)) // 0 > fmt.Println(testing.AllocsPerRun(1, g)) // 1 > fmt.Println(testing.AllocsPerRun(1, h)) // 1 > } > > /* The result: > > N f g H > --- --- --- --- > >=9 0 1 1 > 8,4,2,1,0 0 0 0 > 6,7 0 1 1 > 3,5 0 1 0 > */ > > Some inaccuracies in testing.AllocsPerRun? > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/golang-nuts/1add30d9-a12a-46fe-a5c2-6cf19ff6928do%40googlegroups.com.