mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 17:30:00 +00:00
Add benchmarks for serializing PodList
This commit is contained in:
parent
acd597dbac
commit
c4ffec336c
@ -25,7 +25,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
|
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
|
||||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
@ -165,6 +165,39 @@ func BenchmarkEncodeProtobufGeneratedMarshal(b *testing.B) {
|
|||||||
b.StopTimer()
|
b.StopTimer()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkEncodeProtobufGeneratedMarshalList10(b *testing.B) {
|
||||||
|
item := benchmarkItemsList(b, 10)
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
if _, err := item.Marshal(); err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.StopTimer()
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkEncodeProtobufGeneratedMarshalList100(b *testing.B) {
|
||||||
|
item := benchmarkItemsList(b, 100)
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
if _, err := item.Marshal(); err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.StopTimer()
|
||||||
|
}
|
||||||
|
|
||||||
|
func BenchmarkEncodeProtobufGeneratedMarshalList1000(b *testing.B) {
|
||||||
|
item := benchmarkItemsList(b, 1000)
|
||||||
|
b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
if _, err := item.Marshal(); err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
b.StopTimer()
|
||||||
|
}
|
||||||
|
|
||||||
// BenchmarkDecodeCodecToInternalProtobuf measures the cost of performing a codec decode,
|
// BenchmarkDecodeCodecToInternalProtobuf measures the cost of performing a codec decode,
|
||||||
// including conversions and any type setting. This is a "full" decode.
|
// including conversions and any type setting. This is a "full" decode.
|
||||||
func BenchmarkDecodeCodecToInternalProtobuf(b *testing.B) {
|
func BenchmarkDecodeCodecToInternalProtobuf(b *testing.B) {
|
||||||
|
@ -27,7 +27,7 @@ import (
|
|||||||
|
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
appsv1 "k8s.io/api/apps/v1"
|
appsv1 "k8s.io/api/apps/v1"
|
||||||
"k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
|
"k8s.io/apimachinery/pkg/api/apitesting/fuzzer"
|
||||||
"k8s.io/apimachinery/pkg/api/apitesting/roundtrip"
|
"k8s.io/apimachinery/pkg/api/apitesting/roundtrip"
|
||||||
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
||||||
@ -424,6 +424,25 @@ func benchmarkItems(b *testing.B) []v1.Pod {
|
|||||||
return items
|
return items
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func benchmarkItemsList(b *testing.B, numItems int) v1.PodList {
|
||||||
|
apiObjectFuzzer := fuzzer.FuzzerFor(FuzzerFuncs, rand.NewSource(benchmarkSeed), legacyscheme.Codecs)
|
||||||
|
items := make([]v1.Pod, numItems)
|
||||||
|
for i := range items {
|
||||||
|
var pod api.Pod
|
||||||
|
apiObjectFuzzer.Fuzz(&pod)
|
||||||
|
pod.Spec.InitContainers, pod.Status.InitContainerStatuses = nil, nil
|
||||||
|
out, err := legacyscheme.Scheme.ConvertToVersion(&pod, v1.SchemeGroupVersion)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
items[i] = *out.(*v1.Pod)
|
||||||
|
}
|
||||||
|
|
||||||
|
return v1.PodList{
|
||||||
|
Items: items,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// BenchmarkEncodeCodec measures the cost of performing a codec encode, which includes
|
// BenchmarkEncodeCodec measures the cost of performing a codec encode, which includes
|
||||||
// reflection (to clear APIVersion and Kind)
|
// reflection (to clear APIVersion and Kind)
|
||||||
func BenchmarkEncodeCodec(b *testing.B) {
|
func BenchmarkEncodeCodec(b *testing.B) {
|
||||||
|
Loading…
Reference in New Issue
Block a user