Skip to content

Commit

Permalink
Add stringer, error, marshaler to benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
thockin committed Jan 29, 2022
1 parent ec7c16c commit af7b868
Showing 1 changed file with 54 additions and 0 deletions.
54 changes: 54 additions & 0 deletions benchmark/benchmark_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,45 @@ func doWithCallDepth(b *testing.B, log logr.Logger) {
}
}

type Tstringer struct{ s string }

func (t Tstringer) String() string {
return t.s
}

//go:noinline
func doStringerValue(b *testing.B, log logr.Logger) {
for i := 0; i < b.N; i++ {
log.Info("this is", "a", Tstringer{"stringer"})
}
}

type Terror struct{ s string }

func (t Terror) Error() string {
return t.s
}

//go:noinline
func doErrorValue(b *testing.B, log logr.Logger) {
for i := 0; i < b.N; i++ {
log.Info("this is", "an", Terror{"error"})
}
}

type Tmarshaler struct{ s string }

func (t Tmarshaler) MarshalLog() interface{} {
return t.s
}

//go:noinline
func doMarshalerValue(b *testing.B, log logr.Logger) {
for i := 0; i < b.N; i++ {
log.Info("this is", "a", Tmarshaler{"marshaler"})
}
}

func BenchmarkDiscardLogInfoOneArg(b *testing.B) {
var log logr.Logger = logr.Discard()
doInfoOneArg(b, log)
Expand Down Expand Up @@ -219,3 +258,18 @@ func BenchmarkFuncrWithCallDepth(b *testing.B) {
var log logr.Logger = funcr.New(noopKV, funcr.Options{})
doWithCallDepth(b, log)
}

func BenchmarkFuncrJSONLogInfoStringerValue(b *testing.B) {
var log logr.Logger = funcr.NewJSON(noopJSON, funcr.Options{})
doStringerValue(b, log)
}

func BenchmarkFuncrJSONLogInfoErrorValue(b *testing.B) {
var log logr.Logger = funcr.NewJSON(noopJSON, funcr.Options{})
doErrorValue(b, log)
}

func BenchmarkFuncrJSONLogInfoMarshalerValue(b *testing.B) {
var log logr.Logger = funcr.NewJSON(noopJSON, funcr.Options{})
doMarshalerValue(b, log)
}

0 comments on commit af7b868

Please sign in to comment.