Skip to content

Commit

Permalink
split the span start/end benchmarks
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed Jun 27, 2024
1 parent 0b1e0b2 commit 82b1cc0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
18 changes: 18 additions & 0 deletions sdk/trace/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/codes"
"go.opentelemetry.io/otel/trace"
)

func TestSetStatus(t *testing.T) {
Expand Down Expand Up @@ -277,3 +278,20 @@ func BenchmarkRecordingSpanSetAttributes(b *testing.B) {
})
}
}

func BenchmarkSpanEnd(b *testing.B) {
tracer := NewTracerProvider().Tracer("")
ctx := trace.ContextWithSpanContext(context.Background(), trace.SpanContext{})

spans := make([]trace.Span, b.N)
for i := 0; i < b.N; i++ {
_, span := tracer.Start(ctx, "")
spans[i] = span
}

b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
spans[i].End()
}
}
8 changes: 7 additions & 1 deletion sdk/trace/trace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2112,11 +2112,17 @@ func BenchmarkTraceStart(b *testing.B) {
tracer := NewTracerProvider().Tracer("")
ctx := trace.ContextWithSpanContext(context.Background(), trace.SpanContext{})

spans := make([]trace.Span, b.N)
b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, span := tracer.Start(ctx, "")
span.End()
spans[i] = span
}

b.StopTimer()
for i := 0; i < b.N; i++ {
spans[i].End()
}
}

0 comments on commit 82b1cc0

Please sign in to comment.