Record validation performance baseline
This commit is contained in:
77
performance_benchmark_test.go
Normal file
77
performance_benchmark_test.go
Normal file
@@ -0,0 +1,77 @@
|
||||
package releasekit_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"testing"
|
||||
|
||||
"gitea.maximumdirect.net/eric/ReleaseKit"
|
||||
)
|
||||
|
||||
func BenchmarkPerformanceFacadeCheck(b *testing.B) {
|
||||
repository, moduleBytes := performanceCheckFixture(b)
|
||||
warmRequest := releasekit.ReleaseRequest{
|
||||
RepositoryDir: repository.work,
|
||||
Product: "Sample App",
|
||||
Version: "v1.2.3",
|
||||
}
|
||||
if _, err := releasekit.Check(context.Background(), warmRequest); err != nil {
|
||||
b.Fatalf("warm benchmark Go build cache: %v", err)
|
||||
}
|
||||
b.Run("GoSuiteOnly", func(b *testing.B) {
|
||||
benchmarkFacadeCheck(b, repository, moduleBytes, releasekit.ValidationSpec{})
|
||||
})
|
||||
b.Run("GoSuiteAndSelectedChecks", func(b *testing.B) {
|
||||
benchmarkFacadeCheck(b, repository, moduleBytes, releasekit.ValidationSpec{
|
||||
GoFormat: true,
|
||||
Markdown: &releasekit.MarkdownValidationSpec{},
|
||||
ModuleDistribution: releasekit.ModuleDistributionValidationSpec{
|
||||
LocalReplacements: true,
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func benchmarkFacadeCheck(b *testing.B, repository publishFixture, moduleBytes int64, validation releasekit.ValidationSpec) {
|
||||
b.Helper()
|
||||
request := releasekit.ReleaseRequest{
|
||||
RepositoryDir: repository.work,
|
||||
Product: "Sample App",
|
||||
Version: "v1.2.3",
|
||||
Validation: validation,
|
||||
}
|
||||
b.ReportAllocs()
|
||||
b.ResetTimer()
|
||||
b.ReportMetric(float64(moduleBytes), "module-bytes/op")
|
||||
for i := 0; i < b.N; i++ {
|
||||
if _, err := releasekit.Check(context.Background(), request); err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func performanceCheckFixture(b *testing.B) (publishFixture, int64) {
|
||||
b.Helper()
|
||||
repository := newPublishFixture(b)
|
||||
writeFile(b, repository.work, "source.go", "package fixture\n\nconst name = \"candidate\"\n")
|
||||
gitRun(b, repository.work, "add", "source.go")
|
||||
gitRun(b, repository.work, "commit", "-m", "Add check benchmark source")
|
||||
if status := gitText(b, repository.work, "status", "--porcelain"); status != "" {
|
||||
b.Fatalf("benchmark candidate is not clean:\n%s", status)
|
||||
}
|
||||
b.Setenv("GOMODCACHE", b.TempDir())
|
||||
b.Setenv("GOCACHE", b.TempDir())
|
||||
b.Setenv("GOWORK", "off")
|
||||
b.Setenv("GOPROXY", "off")
|
||||
b.Setenv("GOSUMDB", "off")
|
||||
var moduleBytes int64
|
||||
for _, name := range []string{"go.mod", "source.go", "fixture_test.go", "race_fixture_test.go"} {
|
||||
contents, err := os.ReadFile(filepath.Join(repository.work, name))
|
||||
if err != nil {
|
||||
b.Fatal(err)
|
||||
}
|
||||
moduleBytes += int64(len(contents))
|
||||
}
|
||||
return repository, moduleBytes
|
||||
}
|
||||
Reference in New Issue
Block a user