-
Notifications
You must be signed in to change notification settings - Fork 0
/
executors_test.go
165 lines (156 loc) · 4.02 KB
/
executors_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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
package rxp_test
import (
"context"
"github.com/brickingsoft/rxp"
"math/rand"
"sync/atomic"
"testing"
)
func RandTask() {
rand.Float64()
}
func TestExecutors_TryExecute(t *testing.T) {
ctx := context.Background()
executors := rxp.New()
defer func(executors rxp.Executors) {
err := executors.CloseGracefully()
if err != nil {
t.Fatal(err)
}
}(executors)
executors.TryExecute(ctx, RandTask)
t.Log("goroutines", executors.Goroutines())
}
// BenchmarkExecutors_Execute
// goos: windows
// goarch: amd64
// pkg: github.com/brickingsoft/rxp
// cpu: 13th Gen Intel(R) Core(TM) i5-13600K
// BenchmarkExecutors_Execute
// BenchmarkExecutors_Execute-20 2636208 429.0 ns/op 0 failed 0 B/op 0 allocs/op
func BenchmarkExecutors_Execute(b *testing.B) {
b.ReportAllocs()
executors := rxp.New()
ctx := context.Background()
failed := new(atomic.Int64)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
err := executors.Execute(ctx, RandTask)
if err != nil {
failed.Add(1)
}
}
})
err := executors.CloseGracefully()
if err != nil {
b.Error(err)
}
b.ReportMetric(float64(failed.Load()), "failed")
}
// BenchmarkExecutors_TryExecute
// goos: windows
// goarch: amd64
// pkg: github.com/brickingsoft/rxp
// cpu: 13th Gen Intel(R) Core(TM) i5-13600K
// BenchmarkExecutors_TryExecute
// BenchmarkExecutors_TryExecute-20 2680070 426.4 ns/op 0 failed 0 B/op 0 allocs/op
func BenchmarkExecutors_TryExecute(b *testing.B) {
b.ReportAllocs()
executors := rxp.New()
ctx := context.Background()
failed := new(atomic.Int64)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
ok := executors.TryExecute(ctx, RandTask)
if !ok {
failed.Add(1)
}
}
})
err := executors.CloseGracefully()
if err != nil {
b.Error(err)
}
b.ReportMetric(float64(failed.Load()), "failed")
}
// BenchmarkTryExecute
// goos: windows
// goarch: amd64
// pkg: github.com/brickingsoft/rxp
// cpu: 13th Gen Intel(R) Core(TM) i5-13600K
// BenchmarkTryExecute
// BenchmarkTryExecute-20 2940900 385.0 ns/op 0 failed 0 B/op 0 allocs/op
func BenchmarkTryExecute(b *testing.B) {
b.ReportAllocs()
executors := rxp.New()
ctx := context.Background()
failed := new(atomic.Int64)
b.ResetTimer()
for i := 0; i < b.N; i++ {
ok := executors.TryExecute(ctx, RandTask)
if !ok {
failed.Add(1)
}
}
err := executors.CloseGracefully()
if err != nil {
b.Error(err)
}
b.ReportMetric(float64(failed.Load()), "failed")
}
// BenchmarkExecutors_UnlimitedExecute
// goos: windows
// goarch: amd64
// pkg: github.com/brickingsoft/rxp
// cpu: 13th Gen Intel(R) Core(TM) i5-13600K
// BenchmarkExecutors_UnlimitedExecute
// BenchmarkExecutors_UnlimitedExecute-20 6444103 186.6 ns/op 0 failed 34 B/op 1 allocs/op
func BenchmarkExecutors_UnlimitedExecute(b *testing.B) {
b.ReportAllocs()
executors := rxp.New()
ctx := context.Background()
failed := new(atomic.Int64)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
err := executors.UnlimitedExecute(ctx, RandTask)
if err != nil {
failed.Add(1)
}
}
})
err := executors.CloseGracefully()
if err != nil {
b.Error(err)
}
b.ReportMetric(float64(failed.Load()), "failed")
}
// BenchmarkExecutors_UnlimitedExecute
// goos: windows
// goarch: amd64
// pkg: github.com/brickingsoft/rxp
// cpu: 13th Gen Intel(R) Core(TM) i5-13600K
// BenchmarkExecutors_DirectExecute
// BenchmarkExecutors_DirectExecute-20 6159405 192.1 ns/op 0 failed 38 B/op 1 allocs/op
func BenchmarkExecutors_DirectExecute(b *testing.B) {
b.ReportAllocs()
executors := rxp.New()
ctx := context.Background()
failed := new(atomic.Int64)
b.ResetTimer()
b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
err := executors.DirectExecute(ctx, RandTask)
if err != nil {
failed.Add(1)
}
}
})
err := executors.CloseGracefully()
if err != nil {
b.Error(err)
}
b.ReportMetric(float64(failed.Load()), "failed")
}