mirror of
https://github.com/open-telemetry/opentelemetry-go.git
synced 2024-12-28 21:09:17 +02:00
Add walk attributes benchmark (#5547)
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 ```
This commit is contained in:
parent
649484ef38
commit
12f0db5215
@ -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")
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user