Skip to content

Commit

Permalink
Added Benchmarks around events (#2405)
Browse files Browse the repository at this point in the history
* Added Benchmarks around events

Also fixed the attribute benchmarks to reflect the # of attributes in the test

* Fix test txt, and too new a version of time

Co-authored-by: Tyler Yahn <[email protected]>
  • Loading branch information
MadVikingGod and MrAlias authored Nov 22, 2021
1 parent 7d92434 commit 051227c
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions sdk/trace/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package trace_test
import (
"context"
"testing"
"time"

"go.opentelemetry.io/otel/attribute"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
Expand Down Expand Up @@ -44,6 +45,7 @@ func BenchmarkSpanWithAttributes_4(b *testing.B) {
span.SetAttributes(
attribute.Bool("key1", false),
attribute.String("key2", "hello"),
attribute.Int64("key3", 123),
attribute.Float64("key4", 123.456),
)
span.End()
Expand All @@ -61,9 +63,11 @@ func BenchmarkSpanWithAttributes_8(b *testing.B) {
span.SetAttributes(
attribute.Bool("key1", false),
attribute.String("key2", "hello"),
attribute.Int64("key3", 123),
attribute.Float64("key4", 123.456),
attribute.Bool("key21", false),
attribute.String("key22", "hello"),
attribute.Int64("key23", 123),
attribute.Float64("key24", 123.456),
)
span.End()
Expand Down Expand Up @@ -114,6 +118,67 @@ func BenchmarkSpanWithAttributes_all_2x(b *testing.B) {
})
}

func BenchmarkSpanWithEvents_4(b *testing.B) {
traceBenchmark(b, "Benchmark Start With 4 Events", func(b *testing.B, t trace.Tracer) {
ctx := context.Background()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, span := t.Start(ctx, "/foo")
span.AddEvent("event1")
span.AddEvent("event2")
span.AddEvent("event3")
span.AddEvent("event4")
span.End()
}
})
}

func BenchmarkSpanWithEvents_8(b *testing.B) {
traceBenchmark(b, "Benchmark Start With 4 Events", func(b *testing.B, t trace.Tracer) {
ctx := context.Background()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, span := t.Start(ctx, "/foo")
span.AddEvent("event1")
span.AddEvent("event2")
span.AddEvent("event3")
span.AddEvent("event4")
span.AddEvent("event5")
span.AddEvent("event6")
span.AddEvent("event7")
span.AddEvent("event8")
span.End()
}
})
}

func BenchmarkSpanWithEvents_WithStackTrace(b *testing.B) {
traceBenchmark(b, "Benchmark Start With 4 Attributes", func(b *testing.B, t trace.Tracer) {
ctx := context.Background()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, span := t.Start(ctx, "/foo")
span.AddEvent("event1", trace.WithStackTrace(true))
span.End()
}
})
}
func BenchmarkSpanWithEvents_WithTimestamp(b *testing.B) {
traceBenchmark(b, "Benchmark Start With 4 Attributes", func(b *testing.B, t trace.Tracer) {
ctx := context.Background()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, span := t.Start(ctx, "/foo")
span.AddEvent("event1", trace.WithTimestamp(time.Unix(0, 0)))
span.End()
}
})
}

func BenchmarkTraceID_DotString(b *testing.B) {
t, _ := trace.TraceIDFromHex("0000000000000001000000000000002a")
sc := trace.NewSpanContext(trace.SpanContextConfig{TraceID: t})
Expand Down

0 comments on commit 051227c

Please sign in to comment.