package main import "testing"
var gbuf []byte var gi int func BenchmarkCopy1(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { m := make(map[string]int, 5) for i := 0; i < 5; i++ { m["100"] = i } for key := range m { copyIface1(key, key) } } } func BenchmarkCopy2(b *testing.B) { b.ReportAllocs() for i := 0; i < b.N; i++ { m := make(map[string]int, 5) for i := 0; i < 5; i++ { m["100"] = i } for key := range m { copyIface2(key, key) } } } func copyIface1(a ...interface{}) { if gi > 0 { copy(gbuf, a[0].(string)) copy(gbuf, a[1].(string)) } } func copyIface2(a interface{}, b interface{}) { if gi > 0 { copy(gbuf, a.(string)) copy(gbuf, b.(string)) } } BenchmarkCopy1-4 3000000 452 ns/op 32 B/op 2 allocs/op BenchmarkCopy2-4 5000000 323 ns/op 0 B/op 0 allocs/op BenchmarkCopy1 key escapes to heap BenchmarkCopy2 key does not escape why ??? -- 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. For more options, visit https://groups.google.com/d/optout.