Skip to content

Commit

Permalink
feat: banchmark goccy/yaml to detect performance regressions (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
theseion committed Apr 8, 2024
1 parent f45c831 commit 62b9de7
Show file tree
Hide file tree
Showing 4 changed files with 1,342 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ repos:
rev: v1.0.0-rc.1
hooks:
- id: go-fmt
- id: go-vet
- id: go-vet-mod
- id: go-imports
- id: golangci-lint
- id: golangci-lint-mod
- id: go-critic
- id: go-test-mod
- id: go-build-mod
Expand Down
2 changes: 2 additions & 0 deletions runner/run_input_override_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ func (s *inputOverrideTestSuite) TestApplyInputOverrideNoAutocompleteHeaders() {
AutocompleteHeaders: func() *bool { b := false; return &b }(),
}
s.Nil(s.cfg.TestOverride.Overrides.AutocompleteHeaders)
//nolint:staticcheck
s.Nil(s.cfg.TestOverride.Overrides.StopMagic)
test.ApplyInputOverrides(&s.cfg.TestOverride.Overrides, &testInput)

Expand All @@ -333,6 +334,7 @@ func (s *inputOverrideTestSuite) TestApplyInputOverrideNoStopMagic() {
StopMagic: func() *bool { b := true; return &b }(),
}
s.Nil(s.cfg.TestOverride.Overrides.AutocompleteHeaders)
//nolint:staticcheck
s.Nil(s.cfg.TestOverride.Overrides.StopMagic)
test.ApplyInputOverrides(&s.cfg.TestOverride.Overrides, &testInput)

Expand Down
19 changes: 19 additions & 0 deletions test/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,22 @@ func (s *filesTestSuite) TestGetFromBadYAML() {

s.Error(err, "reading yaml should fail")
}

// This test guards against performance regressions in goccy/yaml. It uses
// an artificially large test file to force the YAML parser to run long
// enough so that the performance difference becomse large enough to test.
// The impacted versions of goccy (v1.9.2 - v1.11.3) will score well above
// 0.01 nano seconds per operation.
func (s *filesTestSuite) TestBenchmarkGetTestsFromFiles() {
result := testing.Benchmark(func(b *testing.B) {
_, err := GetTestsFromFiles("testdata/TestCheckBenchmarkCheckFiles.yaml")
if err != nil {
b.FailNow()
}
})
nsPerOp := float64(result.T.Nanoseconds()) / float64(result.N)
s.T().Logf("Nano seconds per operation: %f", nsPerOp)
if nsPerOp > 0.01 {
s.FailNow("Nano seconds per operation exceeded limit for benchmark: ", nsPerOp)
}
}
Loading

0 comments on commit 62b9de7

Please sign in to comment.