| 72 | } |
| 73 | |
| 74 | func BenchmarkExamples(b *testing.B) { |
| 75 | ctx := context.Background() |
| 76 | examples, err := filepath.Abs(filepath.Join("..", "..", "examples")) |
| 77 | if err != nil { |
| 78 | b.Fatal(err) |
| 79 | } |
| 80 | files, err := os.ReadDir(examples) |
| 81 | if err != nil { |
| 82 | b.Fatal(err) |
| 83 | } |
| 84 | for _, replay := range files { |
| 85 | if !replay.IsDir() { |
| 86 | continue |
| 87 | } |
| 88 | tc := replay.Name() |
| 89 | b.Run(tc, func(b *testing.B) { |
| 90 | path := filepath.Join(examples, tc) |
| 91 | for i := 0; i < b.N; i++ { |
| 92 | var stderr bytes.Buffer |
| 93 | opts := &cmd.Options{ |
| 94 | Env: cmd.Env{}, |
| 95 | Stderr: &stderr, |
| 96 | } |
| 97 | cmd.Generate(ctx, path, "", opts) |
| 98 | } |
| 99 | }) |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | type textContext struct { |
| 104 | Mutate func(*testing.T, string) func(*config.Config) |