diff --git a/sdk/log/record_test.go b/sdk/log/record_test.go index e53cf3410d6..5a16267b8b3 100644 --- a/sdk/log/record_test.go +++ b/sdk/log/record_test.go @@ -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")