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.
4
5package runtime_test
6
7import (
8	"io"
9	"testing"
10)
11
12var errf error
13
14func errfn() error {
15	return errf
16}
17
18func errfn1() error {
19	return io.EOF
20}
21
22func BenchmarkIfaceCmp100(b *testing.B) {
23	for i := 0; i < b.N; i++ {
24		for j := 0; j < 100; j++ {
25			if errfn() == io.EOF {
26				b.Fatal("bad comparison")
27			}
28		}
29	}
30}
31
32func BenchmarkIfaceCmpNil100(b *testing.B) {
33	for i := 0; i < b.N; i++ {
34		for j := 0; j < 100; j++ {
35			if errfn1() == nil {
36				b.Fatal("bad comparison")
37			}
38		}
39	}
40}
41
42func BenchmarkDefer(b *testing.B) {
43	for i := 0; i < b.N; i++ {
44		defer1()
45	}
46}
47
48func defer1() {
49	defer func(x, y, z int) {
50		if recover() != nil || x != 1 || y != 2 || z != 3 {
51			panic("bad recover")
52		}
53	}(1, 2, 3)
54	return
55}
56
57func BenchmarkDefer10(b *testing.B) {
58	for i := 0; i < b.N/10; i++ {
59		defer2()
60	}
61}
62
63func defer2() {
64	for i := 0; i < 10; i++ {
65		defer func(x, y, z int) {
66			if recover() != nil || x != 1 || y != 2 || z != 3 {
67				panic("bad recover")
68			}
69		}(1, 2, 3)
70	}
71}
72
73func BenchmarkDeferMany(b *testing.B) {
74	for i := 0; i < b.N; i++ {
75		defer func(x, y, z int) {
76			if recover() != nil || x != 1 || y != 2 || z != 3 {
77				panic("bad recover")
78			}
79		}(1, 2, 3)
80	}
81}
82