BenchmarkValidation benchmarks the validation phase
(b *testing.B)
| 264 | |
| 265 | // BenchmarkValidation benchmarks the validation phase |
| 266 | func BenchmarkValidation(b *testing.B) { |
| 267 | tmpDir, err := os.MkdirTemp("", "bench-validate") |
| 268 | if err != nil { |
| 269 | b.Fatal(err) |
| 270 | } |
| 271 | defer os.RemoveAll(tmpDir) |
| 272 | |
| 273 | testContent := `--- |
| 274 | on: pull_request |
| 275 | permissions: |
| 276 | contents: read |
| 277 | issues: read |
| 278 | pull-requests: read |
| 279 | engine: copilot |
| 280 | tools: |
| 281 | github: |
| 282 | mode: remote |
| 283 | toolsets: [default] |
| 284 | bash: ["git status"] |
| 285 | strict: true |
| 286 | timeout-minutes: 10 |
| 287 | --- |
| 288 | |
| 289 | # Validation Benchmark |
| 290 | |
| 291 | Test validation performance. |
| 292 | ` |
| 293 | |
| 294 | testFile := filepath.Join(tmpDir, "validate.md") |
| 295 | if err := os.WriteFile(testFile, []byte(testContent), 0644); err != nil { |
| 296 | b.Fatal(err) |
| 297 | } |
| 298 | |
| 299 | compiler := NewCompiler(WithNoEmit(true)) |
| 300 | compiler.SetStrictMode(true) |
| 301 | compiler.SetQuiet(true) |
| 302 | |
| 303 | workflowData, err := compiler.ParseWorkflowFile(testFile) |
| 304 | if err != nil { |
| 305 | b.Fatal(err) |
| 306 | } |
| 307 | |
| 308 | // Warm up: run once before timing to prime one-time caches (schema compilation, etc.) |
| 309 | if err := compiler.validateWorkflowData(workflowData, testFile); err != nil { |
| 310 | b.Fatal(err) |
| 311 | } |
| 312 | |
| 313 | b.ResetTimer() |
| 314 | b.ReportAllocs() |
| 315 | for b.Loop() { |
| 316 | if err := compiler.validateWorkflowData(workflowData, testFile); err != nil { |
| 317 | b.Fatalf("validateWorkflowData failed: %v", err) |
| 318 | } |
| 319 | } |
| 320 | } |
| 321 | |
| 322 | // BenchmarkYAMLGeneration benchmarks YAML generation from workflow data |
| 323 | func BenchmarkYAMLGeneration(b *testing.B) { |
nothing calls this directly
no test coverage detected