Skip to content

Commit

Permalink
Add walk attributes benchmark (#5547)
Browse files Browse the repository at this point in the history
This adds a benchmark for `record.WalkAttributes`.

Part of #5054.

```
BenchmarkWalkAttributes/1_attributes-10                 346989372                3.449 ns/op           0 B/op          0 allocs/op
BenchmarkWalkAttributes/10_attributes-10                345712522                3.459 ns/op           0 B/op          0 allocs/op
BenchmarkWalkAttributes/100_attributes-10               349380534                3.455 ns/op           0 B/op          0 allocs/op
BenchmarkWalkAttributes/1000_attributes-10              342041373                3.484 ns/op           0 B/op          0 allocs/op
```
  • Loading branch information
dmathieu committed Jun 27, 2024
1 parent 649484e commit 12f0db5
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions sdk/log/record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,35 @@ func TestTruncate(t *testing.T) {
}
}

func BenchmarkWalkAttributes(b *testing.B) {
for _, tt := range []struct {
attrCount int
}{
{attrCount: 1},
{attrCount: 10},
{attrCount: 100},
{attrCount: 1000},
} {
b.Run(fmt.Sprintf("%d attributes", tt.attrCount), func(b *testing.B) {
record := &Record{}
for i := 0; i < tt.attrCount; i++ {
record.SetAttributes(
log.String(fmt.Sprintf("key-%d", tt.attrCount), "value"),
)
}

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
record.WalkAttributes(func(log.KeyValue) bool {
return true
})
}
})
}
}

func BenchmarkSetAddAttributes(b *testing.B) {
kv := log.String("key", "value")

Expand Down

0 comments on commit 12f0db5

Please sign in to comment.