@@ -3,10 +3,10 @@ package routing_test
3
3
import (
4
4
"fmt"
5
5
"runtime/metrics"
6
- "sync"
7
6
"testing"
8
7
"time"
9
8
9
+ "github.com/benburkert/pbench"
10
10
"github.com/stretchr/testify/assert"
11
11
"github.com/zalando/skipper/eskip"
12
12
"github.com/zalando/skipper/routing"
@@ -131,29 +131,27 @@ func benchmarkIncInflightRequests(b *testing.B, name string, goroutines int) {
131
131
const key string = "some key"
132
132
const mapSize int = 10000
133
133
134
- b .Run (name , func (b * testing.B ) {
134
+ percentileBench := pbench .New (b )
135
+ percentileBench .ReportPercentile (0.95 )
136
+ percentileBench .ReportPercentile (0.99 )
137
+
138
+ percentileBench .Run (name , func (b * pbench.B ) {
135
139
r := routing .NewEndpointRegistry (routing.RegistryOptions {})
136
140
for i := 1 ; i < mapSize ; i ++ {
137
141
r .IncInflightRequest (fmt .Sprintf ("foo-%d" , i ))
138
142
}
139
143
r .IncInflightRequest (key )
140
144
r .IncInflightRequest (key )
141
-
142
- wg := sync.WaitGroup {}
143
145
b .ResetTimer ()
144
- for i := 0 ; i < goroutines ; i ++ {
145
- wg .Add (1 )
146
- go func () {
147
- defer wg .Done ()
148
- for n := 0 ; n < b .N / goroutines ; n ++ {
149
- r .IncInflightRequest (key )
150
- }
151
- }()
152
- }
153
- wg .Wait ()
154
146
155
- printTotalMutexWaitTime (b )
147
+ b .RunParallel (func (pb * pbench.PB ) {
148
+ for pb .Next () {
149
+ r .IncInflightRequest (key )
150
+ }
151
+ })
156
152
})
153
+
154
+ printTotalMutexWaitTime (b )
157
155
}
158
156
159
157
func BenchmarkIncInflightRequests (b * testing.B ) {
@@ -167,31 +165,29 @@ func benchmarkGetInflightRequests(b *testing.B, name string, goroutines int) {
167
165
const key string = "some key"
168
166
const mapSize int = 10000
169
167
170
- b .Run (name , func (b * testing.B ) {
168
+ percentileBench := pbench .New (b )
169
+ percentileBench .ReportPercentile (0.95 )
170
+ percentileBench .ReportPercentile (0.99 )
171
+
172
+ percentileBench .Run (name , func (b * pbench.B ) {
171
173
r := routing .NewEndpointRegistry (routing.RegistryOptions {})
172
174
for i := 1 ; i < mapSize ; i ++ {
173
175
r .IncInflightRequest (fmt .Sprintf ("foo-%d" , i ))
174
176
}
175
177
r .IncInflightRequest (key )
176
178
r .IncInflightRequest (key )
179
+ b .ResetTimer ()
177
180
178
181
var dummy int64
179
- wg := sync.WaitGroup {}
180
- b .ResetTimer ()
181
- for i := 0 ; i < goroutines ; i ++ {
182
- wg .Add (1 )
183
- go func () {
184
- defer wg .Done ()
185
- for n := 0 ; n < b .N / goroutines ; n ++ {
186
- dummy = r .GetMetrics (key ).InflightRequests ()
187
- }
188
- }()
189
- }
182
+ b .RunParallel (func (pb * pbench.PB ) {
183
+ for pb .Next () {
184
+ dummy = r .GetMetrics (key ).InflightRequests ()
185
+ }
186
+ })
190
187
dummy ++
191
- wg .Wait ()
192
-
193
- printTotalMutexWaitTime (b )
194
188
})
189
+
190
+ printTotalMutexWaitTime (b )
195
191
}
196
192
197
193
func BenchmarkGetInflightRequests (b * testing.B ) {
0 commit comments