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 [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/golang-nuts/44bdea3f-762e-4200-9283-de318d7393a1o%40googlegroups.com.