diff --git a/trace/config_test.go b/trace/config_test.go index da341d06e..6e1c7e033 100644 --- a/trace/config_test.go +++ b/trace/config_test.go @@ -227,61 +227,174 @@ var ( ) func BenchmarkNewTracerConfig(b *testing.B) { - opts := []TracerOption{ - WithInstrumentationVersion("testing version"), - WithSchemaURL("testing URL"), - } + 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() - 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), - } + 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() - 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), - } + 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() - 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), - } + 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() - 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...) + } + }) } }