-
Notifications
You must be signed in to change notification settings - Fork 8
/
bench_recover_test.go
56 lines (47 loc) · 946 Bytes
/
bench_recover_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
package tnt
import "testing"
func BenchmarkCallWithDefer(b *testing.B) {
nothingWithDefer := func(a, b int) (result int) {
defer func() {
}()
result = a + b
return
}
for n := 0; n < b.N; n++ {
nothingWithDefer(1, 2)
}
}
func BenchmarkCallWithRecover(b *testing.B) {
nothingWithRecover := func(a, b int) (result int) {
defer func() {
if r := recover(); r != nil {
result = 0
}
}()
result = a + b
return
}
for n := 0; n < b.N; n++ {
nothingWithRecover(1, 2)
}
}
func BenchmarkCallWithFinishFunction(b *testing.B) {
nothingWithFinishFunction := func(a, b int) (result int) {
finish := func() {}
result = a + b
finish()
return
}
for n := 0; n < b.N; n++ {
nothingWithFinishFunction(1, 2)
}
}
func BenchmarkCallWithoutRecover(b *testing.B) {
nothingWithoutRecover := func(a, b int) (result int) {
result = a + b
return
}
for n := 0; n < b.N; n++ {
nothingWithoutRecover(1, 2)
}
}