@@ -164,18 +164,18 @@ func BenchmarkProcessor(gb *testing.B) {
164
164
}
165
165
166
166
func Benchmark (b * testing.B ) {
167
- const K = 64 // number of metrics
168
- const S = 3 // number of streams
169
- P := runtime .GOMAXPROCS (0 ) // number of routines
170
- if P > K {
167
+ const numMetrics = 64
168
+ const numStreams = 3
169
+ numRoutines := runtime .GOMAXPROCS (0 )
170
+ if numRoutines > numMetrics {
171
171
b .Fatal ("increase K" )
172
172
}
173
173
174
- var id atomic.Int64
175
- id .Store (- 1 )
174
+ var metricID atomic.Int64
175
+ metricID .Store (- 1 )
176
176
177
177
var init sync.WaitGroup
178
- init .Add (P )
178
+ init .Add (numRoutines )
179
179
wait := make (chan struct {})
180
180
181
181
start := time .Now ()
@@ -190,16 +190,16 @@ func Benchmark(b *testing.B) {
190
190
close (wait )
191
191
}()
192
192
193
- k := K / P
193
+ batchSize := numMetrics / numRoutines
194
194
b .RunParallel (func (pb * testing.PB ) {
195
195
md := pmetric .NewMetrics ()
196
- ms := make ([]pmetric.Metric , k )
196
+ ms := make ([]pmetric.Metric , batchSize )
197
197
for i := range ms {
198
198
m := md .ResourceMetrics ().AppendEmpty ().ScopeMetrics ().AppendEmpty ().Metrics ().AppendEmpty ()
199
- mid := id .Add (1 )
199
+ mid := metricID .Add (1 )
200
200
m .SetName (fmt .Sprintf ("metric-%d" , mid ))
201
201
sum := m .SetEmptySum ()
202
- for s := range S {
202
+ for s := range numStreams {
203
203
dp := sum .DataPoints ().AppendEmpty ()
204
204
dp .Attributes ().PutInt ("s" , int64 (s ))
205
205
dp .SetIntValue (rand .Int64N (100 ))
@@ -227,7 +227,7 @@ func Benchmark(b *testing.B) {
227
227
})
228
228
b .StopTimer ()
229
229
230
- dps := K / P * S * b .N
230
+ dps := batchSize * numStreams * b .N
231
231
require .Equal (b , int64 (dps ), sink .Load ())
232
232
}
233
233
0 commit comments