Skip to content

Commit af7b868

Browse files
committed
Add stringer, error, marshaler to benchmark
1 parent ec7c16c commit af7b868

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

benchmark/benchmark_test.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,45 @@ func doWithCallDepth(b *testing.B, log logr.Logger) {
102102
}
103103
}
104104

105+
type Tstringer struct{ s string }
106+
107+
func (t Tstringer) String() string {
108+
return t.s
109+
}
110+
111+
//go:noinline
112+
func doStringerValue(b *testing.B, log logr.Logger) {
113+
for i := 0; i < b.N; i++ {
114+
log.Info("this is", "a", Tstringer{"stringer"})
115+
}
116+
}
117+
118+
type Terror struct{ s string }
119+
120+
func (t Terror) Error() string {
121+
return t.s
122+
}
123+
124+
//go:noinline
125+
func doErrorValue(b *testing.B, log logr.Logger) {
126+
for i := 0; i < b.N; i++ {
127+
log.Info("this is", "an", Terror{"error"})
128+
}
129+
}
130+
131+
type Tmarshaler struct{ s string }
132+
133+
func (t Tmarshaler) MarshalLog() interface{} {
134+
return t.s
135+
}
136+
137+
//go:noinline
138+
func doMarshalerValue(b *testing.B, log logr.Logger) {
139+
for i := 0; i < b.N; i++ {
140+
log.Info("this is", "a", Tmarshaler{"marshaler"})
141+
}
142+
}
143+
105144
func BenchmarkDiscardLogInfoOneArg(b *testing.B) {
106145
var log logr.Logger = logr.Discard()
107146
doInfoOneArg(b, log)
@@ -219,3 +258,18 @@ func BenchmarkFuncrWithCallDepth(b *testing.B) {
219258
var log logr.Logger = funcr.New(noopKV, funcr.Options{})
220259
doWithCallDepth(b, log)
221260
}
261+
262+
func BenchmarkFuncrJSONLogInfoStringerValue(b *testing.B) {
263+
var log logr.Logger = funcr.NewJSON(noopJSON, funcr.Options{})
264+
doStringerValue(b, log)
265+
}
266+
267+
func BenchmarkFuncrJSONLogInfoErrorValue(b *testing.B) {
268+
var log logr.Logger = funcr.NewJSON(noopJSON, funcr.Options{})
269+
doErrorValue(b, log)
270+
}
271+
272+
func BenchmarkFuncrJSONLogInfoMarshalerValue(b *testing.B) {
273+
var log logr.Logger = funcr.NewJSON(noopJSON, funcr.Options{})
274+
doMarshalerValue(b, log)
275+
}

0 commit comments

Comments
 (0)