-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3669 from justinsb/benchmark_swagger_unpack
Add benchmarks to measure impact of swagger parsing
- Loading branch information
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 for swagger parsing (UnmarshalJSON) | ||
func BenchmarkSwaggerUnmarshalJSON(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 for loading assets packed into the binary | ||
func BenchmarkAssetRead(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) | ||
} | ||
} |