diff --git a/pkg/api/testing/serialization_test.go b/pkg/api/testing/serialization_test.go index d47fad73fd7..85f41d674dd 100644 --- a/pkg/api/testing/serialization_test.go +++ b/pkg/api/testing/serialization_test.go @@ -545,8 +545,9 @@ func BenchmarkDecodeIntoJSON(b *testing.B) { b.StopTimer() } -// BenchmarkDecodeJSON provides a baseline for JSON decode performance -func BenchmarkDecodeIntoJSONCodecGen(b *testing.B) { +// BenchmarkDecodeIntoJSONCodecGenConfigFast provides a baseline +// for JSON decode performance with jsoniter.ConfigFast +func BenchmarkDecodeIntoJSONCodecGenConfigFast(b *testing.B) { kcodec := testapi.Default.Codec() items := benchmarkItems(b) width := len(items) @@ -568,3 +569,29 @@ func BenchmarkDecodeIntoJSONCodecGen(b *testing.B) { } b.StopTimer() } + +// BenchmarkDecodeIntoJSONCodecGenConfigCompatibleWithStandardLibrary +// provides a baseline for JSON decode performance +// with jsoniter.ConfigCompatibleWithStandardLibrary +func BenchmarkDecodeIntoJSONCodecGenConfigCompatibleWithStandardLibrary(b *testing.B) { + kcodec := testapi.Default.Codec() + items := benchmarkItems(b) + width := len(items) + encoded := make([][]byte, width) + for i := range items { + data, err := runtime.Encode(kcodec, &items[i]) + if err != nil { + b.Fatal(err) + } + encoded[i] = data + } + + b.ResetTimer() + for i := 0; i < b.N; i++ { + obj := v1.Pod{} + if err := jsoniter.ConfigCompatibleWithStandardLibrary.Unmarshal(encoded[i%width], &obj); err != nil { + b.Fatal(err) + } + } + b.StopTimer() +}