Skip to content

Commit

Permalink
Add benchmarks to measure impact of swagger parsing
Browse files Browse the repository at this point in the history
Example results:

BenchmarkSwaggerParse-72               2         882910241 ns/op
BenchmarkAsssetUnpack-72              62          19654866 ns/op
  • Loading branch information
justinsb committed Mar 3, 2021
1 parent 1d524b6 commit 05deea0
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions kyaml/openapi/openapi_benchmark_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright 2021 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0

package openapi

import (
"path/filepath"
"testing"

"github.com/go-openapi/spec"
"sigs.k8s.io/kustomize/kyaml/openapi/kubernetesapi"
)

// Benchmark that measures the performance impact of swagger parsing
func BenchmarkSwaggerParse(t *testing.B) {
version := kubernetesOpenAPIDefaultVersion

// parse the swagger, this should never fail
assetName := filepath.Join(
"kubernetesapi",
version,
"swagger.json")

b := kubernetesapi.OpenAPIMustAsset[version](assetName)

for i := 0; i < t.N; i++ {
var swagger spec.Swagger
if err := swagger.UnmarshalJSON(b); err != nil {
t.Fatalf("swagger.UnmarshalJSON failed: %v", err)
}
}
}

// Benchmark that measures the performance impact of swagger parsing
func BenchmarkAsssetUnpack(t *testing.B) {
for i := 0; i < t.N; i++ {
version := kubernetesOpenAPIDefaultVersion

// parse the swagger, this should never fail
assetName := filepath.Join(
"kubernetesapi",
version,
"swagger.json")

kubernetesapi.OpenAPIMustAsset[version](assetName)
}
}

0 comments on commit 05deea0

Please sign in to comment.