mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
perf: optimize Gvk.ApiVersion()
Convert Gvk.ApiVersion() from using strings.Builder to raw string concatenation. The logic in Gvk.ApiVersion() is simple enough that raw concatenation executes quicker and consumes less memory.
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
package resid
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
@@ -129,6 +130,23 @@ func TestApiVersion(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func BenchmarkApiVersion(b *testing.B) {
|
||||
for i, bench := range []Gvk{
|
||||
{Kind: "k"},
|
||||
{Version: "v", Kind: "k"},
|
||||
{Group: "g", Kind: "k"},
|
||||
{Group: "g", Version: "v"},
|
||||
{Group: "g", Version: "v", Kind: "k"},
|
||||
{Group: "bitnami.com", Version: "v1alpha1", Kind: "SealedSecret"},
|
||||
} {
|
||||
b.Run(fmt.Sprintf("%d", i), func(b *testing.B) {
|
||||
for i := 0; i < b.N; i++ {
|
||||
_ = bench.ApiVersion()
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestStringWoEmptyField(t *testing.T) {
|
||||
for _, hey := range stringTests {
|
||||
assert.Equal(t, hey.r, hey.x.StringWoEmptyField())
|
||||
|
||||
Reference in New Issue
Block a user