cloudflare/pint
Publicmirrored from https://github.com/cloudflare/pintAvailable
cmd/pint/bench_test.go
47lines · modecode
| 1 | package main |
| 2 | |
| 3 | import ( |
| 4 | "context" |
| 5 | "log/slog" |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/prometheus/client_golang/prometheus" |
| 9 | |
| 10 | "github.com/cloudflare/pint/internal/config" |
| 11 | "github.com/cloudflare/pint/internal/discovery" |
| 12 | "github.com/cloudflare/pint/internal/git" |
| 13 | "github.com/cloudflare/pint/internal/log" |
| 14 | ) |
| 15 | |
| 16 | func BenchmarkFindEntries(b *testing.B) { |
| 17 | log.Setup(slog.LevelError, true) |
| 18 | |
| 19 | finder := discovery.NewGlobFinder( |
| 20 | []string{"bench/rules"}, |
| 21 | git.NewPathFilter(nil, nil, nil), |
| 22 | ) |
| 23 | for n := 0; n < b.N; n++ { |
| 24 | _, _ = finder.Find() |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | func BenchmarkCheckRules(b *testing.B) { |
| 29 | log.Setup(slog.LevelError, true) |
| 30 | |
| 31 | finder := discovery.NewGlobFinder( |
| 32 | []string{"bench/rules"}, |
| 33 | git.NewPathFilter(nil, nil, nil), |
| 34 | ) |
| 35 | entries, err := finder.Find() |
| 36 | if err != nil { |
| 37 | b.Errorf("Find() error: %s", err) |
| 38 | b.FailNow() |
| 39 | } |
| 40 | |
| 41 | ctx := context.Background() |
| 42 | cfg, _ := config.Load("", false) |
| 43 | gen := config.NewPrometheusGenerator(cfg, prometheus.NewRegistry()) |
| 44 | for n := 0; n < b.N; n++ { |
| 45 | _, _ = checkRules(ctx, 10, true, gen, cfg, entries) |
| 46 | } |
| 47 | } |