mirror of https://github.com/k3s-io/k3s
add benchmark for ConfigCompatibleWithStandardLibrary
parent
07bf6e8088
commit
5da7b11a31
|
@ -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()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue