-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnozzle_bench_test.go
98 lines (75 loc) · 1.96 KB
/
nozzle_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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package nozzle_test
import (
"testing"
"time"
"github.com/justindfuller/nozzle"
)
func BenchmarkNozzle_DoBool_Open(b *testing.B) {
noz := nozzle.New(nozzle.Options[any]{Interval: time.Millisecond * 10, AllowedFailurePercent: 50})
act := newActor(b.N)
for i := 0; i < b.N; i++ {
noz.DoBool(func() (any, bool) {
err := act.do()
return nil, err == nil
})
}
}
func BenchmarkNozzle_DoBool_Closed(b *testing.B) {
noz := nozzle.New(nozzle.Options[any]{Interval: time.Millisecond * 10, AllowedFailurePercent: 50})
act := newActor(0)
for i := 0; i < b.N; i++ {
noz.DoBool(func() (any, bool) {
err := act.do()
return nil, err == nil
})
}
}
func BenchmarkNozzle_DoBool_Half(b *testing.B) {
noz := nozzle.New(nozzle.Options[any]{Interval: time.Millisecond * 10, AllowedFailurePercent: 50})
act := newActor(b.N / 2)
for i := 0; i < b.N; i++ {
noz.DoBool(func() (any, bool) {
err := act.do()
return nil, err == nil
})
}
}
func BenchmarkNozzle_DoError_Open(b *testing.B) {
noz := nozzle.New(nozzle.Options[any]{Interval: time.Millisecond * 10, AllowedFailurePercent: 50})
act := newActor(b.N)
for i := 0; i < b.N; i++ {
noz.DoError(func() (any, error) {
err := act.do()
return nil, err
})
}
}
func BenchmarkNozzle_DoError_Closed(b *testing.B) {
noz := nozzle.New(nozzle.Options[any]{Interval: time.Millisecond * 10, AllowedFailurePercent: 50})
act := newActor(0)
for i := 0; i < b.N; i++ {
noz.DoError(func() (any, error) {
err := act.do()
return nil, err
})
}
}
func BenchmarkNozzle_DoError_Half(b *testing.B) {
noz := nozzle.New(nozzle.Options[any]{Interval: time.Millisecond * 10, AllowedFailurePercent: 50})
act := newActor(b.N / 2)
for i := 0; i < b.N; i++ {
noz.DoError(func() (any, error) {
err := act.do()
return nil, err
})
}
}
func BenchmarkNozzle_DoBool_Control(b *testing.B) {
act := newActor(b.N / 2)
for i := 0; i < b.N; i++ {
if err := act.do(); err != nil {
continue
}
continue
}
}