github.com/xushiwei/go@v0.0.0-20130601165731-2b9d83f45bc9/test/fixedbugs/issue4618.go (about) 1 // run 2 3 // Copyright 2013 The Go Authors. All rights reserved. 4 // Use of this source code is governed by a BSD-style 5 // license that can be found in the LICENSE file. 6 7 package main 8 9 import ( 10 "fmt" 11 "os" 12 "testing" 13 ) 14 15 type T struct { int } 16 17 var globl *T 18 19 func F() { 20 t := &T{} 21 globl = t 22 } 23 24 func G() { 25 t := &T{} 26 _ = t 27 } 28 29 func main() { 30 nf := testing.AllocsPerRun(100, F) 31 ng := testing.AllocsPerRun(100, G) 32 if int(nf) != 1 { 33 fmt.Printf("AllocsPerRun(100, F) = %v, want 1\n", nf) 34 os.Exit(1) 35 } 36 if int(ng) != 0 { 37 fmt.Printf("AllocsPerRun(100, G) = %v, want 0\n", ng) 38 os.Exit(1) 39 } 40 }