-
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.
Add benchmarks to measure impact of swagger parsing
Example results: BenchmarkSwaggerParse-72 2 882910241 ns/op BenchmarkAsssetUnpack-72 62 19654866 ns/op
- 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 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) | ||
} | ||
} |