-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmark_test.go
75 lines (68 loc) · 1.19 KB
/
benchmark_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
package retry
import (
"context"
"errors"
"testing"
"time"
)
//go:noinline
func dummyFunc() {}
func BenchmarkContinue(b *testing.B) {
policy := &Policy{
MaxCount: 100,
}
for i := 0; i < b.N; i++ {
retrier := policy.Start(context.Background())
for retrier.Continue() {
dummyFunc()
}
}
}
func BenchmarkContinueSuccess(b *testing.B) {
policy := &Policy{
MaxCount: 100,
}
for i := 0; i < b.N; i++ {
retrier := policy.Start(context.Background())
retrier.Continue()
dummyFunc()
}
}
func BenchmarkDo(b *testing.B) {
err := errors.New("error")
policy := &Policy{
MaxCount: 100,
}
for i := 0; i < b.N; i++ {
policy.Do(context.Background(), func() error {
dummyFunc()
return err
})
}
}
func BenchmarkDoSuccess(b *testing.B) {
policy := &Policy{
MaxCount: 100,
}
for i := 0; i < b.N; i++ {
policy.Do(context.Background(), func() error {
dummyFunc()
return nil
})
}
}
func BenchmarkDo_Parallel(b *testing.B) {
err := errors.New("error")
policy := &Policy{
MaxCount: 100,
Jitter: 1 * time.Nanosecond,
}
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
policy.Do(context.Background(), func() error {
dummyFunc()
return err
})
}
})
}