1 // Copyright 2012 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.
28 func BenchmarkIfaceCmp100(b
*testing
.B
) {
29 for i
:= 0; i
< b
.N
; i
++ {
30 for j
:= 0; j
< 100; j
++ {
31 if errfn() == io
.EOF
{
32 b
.Fatal("bad comparison")
38 func BenchmarkIfaceCmpNil100(b
*testing
.B
) {
39 for i
:= 0; i
< b
.N
; i
++ {
40 for j
:= 0; j
< 100; j
++ {
42 b
.Fatal("bad comparison")
48 func BenchmarkDefer(b
*testing
.B
) {
49 for i
:= 0; i
< b
.N
; i
++ {
55 defer func(x
, y
, z
int) {
56 if recover() != nil || x
!= 1 || y
!= 2 || z
!= 3 {
63 func BenchmarkDefer10(b
*testing
.B
) {
64 for i
:= 0; i
< b
.N
/10; i
++ {
70 for i
:= 0; i
< 10; i
++ {
71 defer func(x
, y
, z
int) {
72 if recover() != nil || x
!= 1 || y
!= 2 || z
!= 3 {
79 func BenchmarkDeferMany(b
*testing
.B
) {
80 for i
:= 0; i
< b
.N
; i
++ {
81 defer func(x
, y
, z
int) {
82 if recover() != nil || x
!= 1 || y
!= 2 || z
!= 3 {
89 /* The go tool is not present in gccgo.
91 // The profiling signal handler needs to know whether it is executing runtime.gogo.
92 // The constant RuntimeGogoBytes in arch_*.h gives the size of the function;
93 // we don't have a way to obtain it from the linker (perhaps someday).
94 // Test that the constant matches the size determined by 'go tool nm -S'.
95 // The value reported will include the padding between runtime.gogo and the
96 // next function in memory. That's fine.
97 func TestRuntimeGogoBytes(t *testing.T) {
98 dir, err := ioutil.TempDir("", "go-build")
100 t.Fatalf("failed to create temp directory: %v", err)
102 defer os.RemoveAll(dir)
104 out, err := exec.Command("go", "build", "-o", dir+"/hello", "../../../test/helloworld.go").CombinedOutput()
106 t.Fatalf("building hello world: %v\n%s", err, out)
109 out, err = exec.Command("go", "tool", "nm", "-S", dir+"/hello").CombinedOutput()
111 t.Fatalf("go tool nm: %v\n%s", err, out)
114 for _, line := range strings.Split(string(out), "\n") {
115 f := strings.Fields(line)
116 if len(f) == 4 && f[3] == "runtime.gogo" {
117 size, _ := strconv.Atoi(f[1])
118 if GogoBytes() != int32(size) {
119 t.Fatalf("RuntimeGogoBytes = %d, should be %d", GogoBytes(), size)
125 t.Fatalf("go tool nm did not report size for runtime.gogo")