-
Notifications
You must be signed in to change notification settings - Fork 0
/
bench_test.go
84 lines (76 loc) · 1.23 KB
/
bench_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package e5
import (
"errors"
"io"
"testing"
)
var testErr error
func BenchmarkHandleNil(b *testing.B) {
for i := 0; i < b.N; i++ {
err := func() (err error) {
defer Handle(&err)
return nil
}()
if err != nil {
b.Fatal()
}
}
}
func BenchmarkHandleErr(b *testing.B) {
for i := 0; i < b.N; i++ {
err := func() (err error) {
defer Handle(&err)
return io.EOF
}()
if !errors.Is(err, io.EOF) {
b.Fatal()
}
}
}
func BenchmarkHandleCheckNil(b *testing.B) {
for i := 0; i < b.N; i++ {
err := func() (err error) {
defer Handle(&err)
Check(nil)
return
}()
if err != nil {
b.Fatal()
}
}
}
func BenchmarkHandleCheck(b *testing.B) {
for i := 0; i < b.N; i++ {
err := func() (err error) {
defer Handle(&err)
Check(io.EOF)
return
}()
if !errors.Is(err, io.EOF) {
b.Fatal()
}
}
}
func BenchmarkHandleCheckDeep(b *testing.B) {
var fn func(int) error
fn = func(i int) (err error) {
defer Handle(&err)
if i == 0 {
return io.EOF
}
Check(fn(i - 1))
return
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
err := fn(30)
if !errors.Is(err, io.EOF) {
b.Fatal()
}
}
}
func BenchmarkStacktrace(b *testing.B) {
for i := 0; i < b.N; i++ {
WrapStacktrace(io.EOF)
}
}