mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
add benchmark for ConfigCompatibleWithStandardLibrary
This commit is contained in:
parent
07bf6e8088
commit
5da7b11a31
@ -545,8 +545,9 @@ func BenchmarkDecodeIntoJSON(b *testing.B) {
|
|||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
}
|
}
|
||||||
|
|
||||||
// BenchmarkDecodeJSON provides a baseline for JSON decode performance
|
// BenchmarkDecodeIntoJSONCodecGenConfigFast provides a baseline
|
||||||
func BenchmarkDecodeIntoJSONCodecGen(b *testing.B) {
|
// for JSON decode performance with jsoniter.ConfigFast
|
||||||
|
func BenchmarkDecodeIntoJSONCodecGenConfigFast(b *testing.B) {
|
||||||
kcodec := testapi.Default.Codec()
|
kcodec := testapi.Default.Codec()
|
||||||
items := benchmarkItems(b)
|
items := benchmarkItems(b)
|
||||||
width := len(items)
|
width := len(items)
|
||||||
@ -568,3 +569,29 @@ func BenchmarkDecodeIntoJSONCodecGen(b *testing.B) {
|
|||||||
}
|
}
|
||||||
b.StopTimer()
|
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
Block a user