Skip to content

Commit 672ba93

Browse files
committed
extend trace start benchmark to include links and attributes
1 parent 82b1cc0 commit 672ba93

File tree

1 file changed

+41
-10
lines changed

1 file changed

+41
-10
lines changed

sdk/trace/trace_test.go

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2112,17 +2112,48 @@ func BenchmarkTraceStart(b *testing.B) {
21122112
tracer := NewTracerProvider().Tracer("")
21132113
ctx := trace.ContextWithSpanContext(context.Background(), trace.SpanContext{})
21142114

2115-
spans := make([]trace.Span, b.N)
2116-
b.ReportAllocs()
2117-
b.ResetTimer()
2115+
l1 := trace.Link{SpanContext: trace.SpanContext{}, Attributes: []attribute.KeyValue{}}
2116+
l2 := trace.Link{SpanContext: trace.SpanContext{}, Attributes: []attribute.KeyValue{}}
21182117

2119-
for i := 0; i < b.N; i++ {
2120-
_, span := tracer.Start(ctx, "")
2121-
spans[i] = span
2122-
}
2118+
links := []trace.Link{l1, l2}
21232119

2124-
b.StopTimer()
2125-
for i := 0; i < b.N; i++ {
2126-
spans[i].End()
2120+
for _, tt := range []struct {
2121+
name string
2122+
options []trace.SpanStartOption
2123+
}{
2124+
{
2125+
name: "with a simple span",
2126+
},
2127+
{
2128+
name: "with several links",
2129+
options: []trace.SpanStartOption{
2130+
trace.WithLinks(links...),
2131+
},
2132+
},
2133+
{
2134+
name: "with attributes",
2135+
options: []trace.SpanStartOption{
2136+
trace.WithAttributes(
2137+
attribute.String("key1", "value1"),
2138+
attribute.String("key2", "value2"),
2139+
),
2140+
},
2141+
},
2142+
} {
2143+
b.Run(tt.name, func(b *testing.B) {
2144+
spans := make([]trace.Span, b.N)
2145+
b.ReportAllocs()
2146+
b.ResetTimer()
2147+
2148+
for i := 0; i < b.N; i++ {
2149+
_, span := tracer.Start(ctx, "", tt.options...)
2150+
spans[i] = span
2151+
}
2152+
2153+
b.StopTimer()
2154+
for i := 0; i < b.N; i++ {
2155+
spans[i].End()
2156+
}
2157+
})
21272158
}
21282159
}

0 commit comments

Comments
 (0)