Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend trace config benchmarks to run each option individually #5566

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
193 changes: 153 additions & 40 deletions trace/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -227,61 +227,174 @@ var (
)

func BenchmarkNewTracerConfig(b *testing.B) {
opts := []TracerOption{
WithInstrumentationVersion("testing version"),
WithSchemaURL("testing URL"),
}

b.ReportAllocs()
b.ResetTimer()
for _, bb := range []struct {
name string
options []TracerOption
}{
{
name: "with no options",
},
{
name: "with an instrumentation version",
options: []TracerOption{
WithInstrumentationVersion("testing version"),
},
},
{
name: "with a schema url",
options: []TracerOption{
WithSchemaURL("testing URL"),
},
},
} {
b.Run(bb.name, func(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
tracerConfig = NewTracerConfig(opts...)
for i := 0; i < b.N; i++ {
tracerConfig = NewTracerConfig(bb.options...)
}
})
}
}

func BenchmarkNewSpanStartConfig(b *testing.B) {
opts := []SpanStartOption{
WithAttributes(attribute.Bool("key", true)),
WithTimestamp(time.Now()),
WithLinks(Link{}),
WithNewRoot(),
WithSpanKind(SpanKindClient),
}

b.ReportAllocs()
b.ResetTimer()
for _, bb := range []struct {
name string
options []SpanStartOption
}{
{
name: "with no options",
},
{
name: "with attributes",
options: []SpanStartOption{
WithAttributes(attribute.Bool("key", true)),
},
},
{
name: "with attributes set multiple times",
options: []SpanStartOption{
WithAttributes(attribute.Bool("key", true)),
WithAttributes(attribute.Bool("secondKey", false)),
},
},
{
name: "with a timestamp",
options: []SpanStartOption{
WithTimestamp(time.Now()),
},
},
{
name: "with links",
options: []SpanStartOption{
WithLinks(Link{}),
},
},
{
name: "with links set multiple times",
options: []SpanStartOption{
WithLinks(Link{}),
WithLinks(Link{}),
},
},
{
name: "with new root",
options: []SpanStartOption{
WithNewRoot(),
},
},
{
name: "with span kind",
options: []SpanStartOption{
WithSpanKind(SpanKindClient),
},
},
} {
b.Run(bb.name, func(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
spanConfig = NewSpanStartConfig(opts...)
for i := 0; i < b.N; i++ {
spanConfig = NewSpanStartConfig(bb.options...)
}
})
}
}

func BenchmarkNewSpanEndConfig(b *testing.B) {
opts := []SpanEndOption{
WithTimestamp(time.Now()),
WithStackTrace(true),
}

b.ReportAllocs()
b.ResetTimer()
for _, bb := range []struct {
name string
options []SpanEndOption
}{
{
name: "with no options",
},
{
name: "with a timestamp",
options: []SpanEndOption{
WithTimestamp(time.Now()),
},
},
{
name: "with stack trace",
options: []SpanEndOption{
WithStackTrace(true),
},
},
} {
b.Run(bb.name, func(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
spanConfig = NewSpanEndConfig(opts...)
for i := 0; i < b.N; i++ {
spanConfig = NewSpanEndConfig(bb.options...)
}
})
}
}

func BenchmarkNewEventConfig(b *testing.B) {
opts := []EventOption{
WithAttributes(attribute.Bool("key", true)),
WithTimestamp(time.Now()),
WithStackTrace(true),
}

b.ReportAllocs()
b.ResetTimer()
for _, bb := range []struct {
name string
options []EventOption
}{
{
name: "with no options",
},
{
name: "with attributes",
options: []EventOption{
WithAttributes(attribute.Bool("key", true)),
},
},
{
name: "with attributes set multiple times",
options: []EventOption{
WithAttributes(attribute.Bool("key", true)),
WithAttributes(attribute.Bool("secondKey", false)),
},
},
{
name: "with a timestamp",
options: []EventOption{
WithTimestamp(time.Now()),
},
},
{
name: "with a stacktrace",
options: []EventOption{
WithStackTrace(true),
},
},
} {
b.Run(bb.name, func(b *testing.B) {
b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
eventConfig = NewEventConfig(opts...)
for i := 0; i < b.N; i++ {
eventConfig = NewEventConfig(bb.options...)
}
})
}
}