Skip to content

Commit

Permalink
Split the set and add attributes benchmarks (#5546)
Browse files Browse the repository at this point in the history
This benchmark currently tests two rather different methods within the
same loop, which makes it hard to see what could be causing a
performance degradation.

Related: #5054.

```
BenchmarkSetAddAttributes/SetAttributes-10              14066331                82.80 ns/op           48 B/op          1 allocs/op
BenchmarkSetAddAttributes/AddAttributes-10              19333711               114.7 ns/op             0 B/op          0 allocs/op
```
  • Loading branch information
dmathieu committed Jun 27, 2024
1 parent cda5094 commit 649484e
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions sdk/log/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -642,12 +642,24 @@ func TestTruncate(t *testing.T) {

func BenchmarkSetAddAttributes(b *testing.B) {
kv := log.String("key", "value")
records := make([]Record, b.N)

b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
records[i].SetAttributes(kv)
records[i].AddAttributes(kv)
}
b.Run("SetAttributes", func(b *testing.B) {
records := make([]Record, b.N)

b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
records[i].SetAttributes(kv)
}
})

b.Run("AddAttributes", func(b *testing.B) {
records := make([]Record, b.N)

b.ResetTimer()
b.ReportAllocs()
for i := 0; i < b.N; i++ {
records[i].AddAttributes(kv)
}
})
}

0 comments on commit 649484e

Please sign in to comment.