Skip to content

Commit 547576d

Browse files
authored
[refactor]: use b.Loop() to simplify the code and improve performance (#7605)
<!-- !! Please DELETE this comment before posting. We appreciate your contribution to the Jaeger project! 👋🎉 --> ## Which problem is this PR solving? - <!-- Example: Resolves #123 --> ## Description of the changes These changes use b.Loop() to simplify the code and improve performance Supported by Go Team, more info: https://go.dev/blog/testing-b-loop ## How was this change tested? - ## Checklist - [x] I have read https://github.com/jaegertracing/jaeger/blob/master/CONTRIBUTING_GUIDELINES.md - [x] I have signed all commits - [ ] I have added unit tests for the new functionality - [x] I have run lint and test steps successfully - for `jaeger`: `make lint test` - for `jaeger-ui`: `npm run lint` and `npm run test` Signed-off-by: vastonus <[email protected]>
1 parent 5fbe3ad commit 547576d

File tree

6 files changed

+12
-15
lines changed

6 files changed

+12
-15
lines changed

cmd/collector/app/queue/bounded_queue_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func BenchmarkBoundedQueue(b *testing.B) {
325325
q.StartConsumers(10, func( /* item */ any) {})
326326
defer q.Stop()
327327

328-
for n := 0; n < b.N; n++ {
328+
for n := 0; b.Loop(); n++ {
329329
q.Produce(n)
330330
}
331331
}
@@ -338,7 +338,7 @@ func BenchmarkBoundedQueueWithFactory(b *testing.B) {
338338
})
339339
defer q.Stop()
340340

341-
for n := 0; n < b.N; n++ {
341+
for n := 0; b.Loop(); n++ {
342342
q.Produce(n)
343343
}
344344
}

cmd/ingester/app/consumer/offset/concurrent_list_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ func extractMin(arr []int64) (int64, []int64) {
139139
// BenchmarkInserts-8 100000000 70.6 ns/op 49 B/op 0 allocs/op
140140
func BenchmarkInserts(b *testing.B) {
141141
l := newConcurrentList(0)
142-
for i := 1; i < b.N; i++ {
142+
for i := 1; b.Loop(); i++ {
143143
l.insert(int64(i))
144144
}
145145
}

internal/gogocodec/codec_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,7 @@ func BenchmarkCodecUnmarshal25Spans(b *testing.B) {
9292
bytes, err := c.Marshal(&trace)
9393
require.NoError(b, err)
9494

95-
b.ResetTimer()
96-
97-
for i := 0; i < b.N; i++ {
95+
for b.Loop() {
9896
var trace model.Trace
9997
err := c.Unmarshal(bytes, &trace)
10098
require.NoError(b, err)

internal/storage/v1/api/spanstore/downsampling_writer_benchmark_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ func BenchmarkDownSamplingWriter_WriteSpan(b *testing.B) {
2828
Ratio: 0.5,
2929
HashSalt: "jaeger-test",
3030
})
31-
b.ResetTimer()
31+
3232
b.ReportAllocs()
33-
for it := 0; it < b.N; it++ {
33+
for b.Loop() {
3434
c.WriteSpan(context.Background(), span)
3535
}
3636
}
@@ -46,10 +46,10 @@ func BenchmarkDownSamplingWriter_HashBytes(b *testing.B) {
4646
for i := 0; i < 16; i++ {
4747
ba[i] = byte(i)
4848
}
49-
b.ResetTimer()
49+
5050
b.ReportAllocs()
5151
h := c.sampler.hasherPool.Get().(*hasher)
52-
for it := 0; it < b.N; it++ {
52+
for b.Loop() {
5353
h.hashBytes()
5454
}
5555
c.sampler.hasherPool.Put(h)
@@ -66,7 +66,7 @@ func BenchmarkDownsamplingWriter_RandomHash(b *testing.B) {
6666
}
6767
c := NewDownsamplingWriter(&noopWriteSpanStore{}, downsamplingOptions)
6868
h := c.sampler.hasherPool.Get().(*hasher)
69-
for it := 0; it < b.N; it++ {
69+
for b.Loop() {
7070
countSmallerThanRatio = 0
7171
for i := 0; i < numberActions; i++ {
7272
low := rand.Uint64()

internal/storage/v2/elasticsearch/tracestore/from_dbmodel_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,8 +882,8 @@ func BenchmarkProtoBatchToInternalTraces(b *testing.B) {
882882
err = json.Unmarshal(data, &dbSpan)
883883
require.NoError(b, err)
884884
jb := []dbmodel.Span{dbSpan}
885-
b.ResetTimer()
886-
for n := 0; n < b.N; n++ {
885+
886+
for b.Loop() {
887887
_, err := FromDBModel(jb)
888888
assert.NoError(b, err)
889889
}

internal/storage/v2/elasticsearch/tracestore/to_dbmodel_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -729,8 +729,7 @@ func BenchmarkInternalTracesToDbSpans(b *testing.B) {
729729
td, err := unmarshaller.UnmarshalTraces(data)
730730
require.NoError(b, err)
731731

732-
b.ResetTimer()
733-
for n := 0; n < b.N; n++ {
732+
for b.Loop() {
734733
batches := ToDBModel(td)
735734
assert.NotEmpty(b, batches)
736735
}

0 commit comments

Comments
 (0)