1// Copyright 2011 The Go Authors. All rights reserved. 2// Use of this source code is governed by a BSD-style 3// license that can be found in the LICENSE file. 4 5package runtime_test 6 7import "testing" 8 9var s int 10 11func BenchmarkCallClosure(b *testing.B) { 12 for i := 0; i < b.N; i++ { 13 s += func(ii int) int { return 2 * ii }(i) 14 } 15} 16 17func BenchmarkCallClosure1(b *testing.B) { 18 for i := 0; i < b.N; i++ { 19 j := i 20 s += func(ii int) int { return 2*ii + j }(i) 21 } 22} 23 24var ss *int 25 26func BenchmarkCallClosure2(b *testing.B) { 27 for i := 0; i < b.N; i++ { 28 j := i 29 s += func() int { 30 ss = &j 31 return 2 32 }() 33 } 34} 35 36func addr1(x int) *int { 37 return func() *int { return &x }() 38} 39 40func BenchmarkCallClosure3(b *testing.B) { 41 for i := 0; i < b.N; i++ { 42 ss = addr1(i) 43 } 44} 45 46func addr2() (x int, p *int) { 47 return 0, func() *int { return &x }() 48} 49 50func BenchmarkCallClosure4(b *testing.B) { 51 for i := 0; i < b.N; i++ { 52 _, ss = addr2() 53 } 54} 55