Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into otelecho-formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
flc1125 committed Nov 26, 2024
2 parents 23c9bc0 + 91a1588 commit 301ecae
Showing 1 changed file with 89 additions and 0 deletions.
89 changes: 89 additions & 0 deletions bridges/otellogr/logsink_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -462,3 +462,92 @@ func TestConvertKVs(t *testing.T) {
})
}
}

func BenchmarkLogSink(b *testing.B) {
message := "body"
keyValues := []any{
"string", "hello",
"int", 42,
"float", 3.14,
"bool", false,
}
err := errors.New("error")

b.Run("Info", func(b *testing.B) {
logSinks := make([]logr.LogSink, b.N)
for i := range logSinks {
logSinks[i] = NewLogSink("")
}

b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
logSinks[n].Info(0, message, keyValues...)
}
})

b.Run("Error", func(b *testing.B) {
logSinks := make([]logr.LogSink, b.N)
for i := range logSinks {
logSinks[i] = NewLogSink("")
}

b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
logSinks[n].Error(err, message, keyValues...)
}
})

b.Run("WithValues", func(b *testing.B) {
logSinks := make([]logr.LogSink, b.N)
for i := range logSinks {
logSinks[i] = NewLogSink("")
}

b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
logSinks[n].WithValues(keyValues...)
}
})

b.Run("WithName", func(b *testing.B) {
logSinks := make([]logr.LogSink, b.N)
for i := range logSinks {
logSinks[i] = NewLogSink("")
}

b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
logSinks[n].WithName("name")
}
})

b.Run("WithName.WithValues", func(b *testing.B) {
logSinks := make([]logr.LogSink, b.N)
for i := range logSinks {
logSinks[i] = NewLogSink("")
}

b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
logSinks[n].WithName("name").WithValues(keyValues...)
}
})

b.Run("(WithName.WithValues).Info", func(b *testing.B) {
logSinks := make([]logr.LogSink, b.N)
for i := range logSinks {
logSinks[i] = NewLogSink("").WithName("name").WithValues(keyValues...)
}

b.ReportAllocs()
b.ResetTimer()
for n := 0; n < b.N; n++ {
logSinks[n].Info(0, message)
}
})
}

0 comments on commit 301ecae

Please sign in to comment.