Skip to content

Commit bf14bb5

Browse files
committed
refactor: add import benchmark profile filter
1 parent 4af9edc commit bf14bb5

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

internal/wire/import_bench_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ const (
2121
importBenchBreakdown = "WIRE_IMPORT_BENCH_BREAKDOWN"
2222
importBenchScenarios = "WIRE_IMPORT_BENCH_SCENARIOS"
2323
importBenchScenarioBD = "WIRE_IMPORT_BENCH_SCENARIO_BREAKDOWN"
24+
importBenchProfile = "WIRE_IMPORT_BENCH_PROFILE"
2425
stockWireCommit = "9c25c9016f6825302537c4efdd5e897976f9c826"
2526
stockWireModulePath = "github.com/google/wire"
2627
currentWireModulePath = "github.com/goforj/wire"
@@ -145,6 +146,18 @@ func TestPrintImportScenarioBenchmarkTable(t *testing.T) {
145146
{localPkgs: 10, depPkgs: 25, external: true, label: "external"},
146147
{localPkgs: 10, depPkgs: 100, external: true, label: "external"},
147148
}
149+
if filter := os.Getenv(importBenchProfile); filter != "" {
150+
filtered := make([]appBenchProfile, 0, len(profiles))
151+
for _, profile := range profiles {
152+
if profile.label == filter {
153+
filtered = append(filtered, profile)
154+
}
155+
}
156+
if len(filtered) == 0 {
157+
t.Fatalf("%s=%q did not match any benchmark profile", importBenchProfile, filter)
158+
}
159+
profiles = filtered
160+
}
148161
rows := make([]importBenchScenarioRow, 0, len(profiles)*6)
149162
for _, profile := range profiles {
150163
shapeFixture := createAppShapeBenchFixture(t, profile.localPkgs, profile.depPkgs, profile.external, currentWireModulePath, repoRoot)

scripts/import-benchmarks.sh

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,13 @@ usage() {
1212
cat <<'EOF'
1313
Usage:
1414
scripts/import-benchmarks.sh table
15-
scripts/import-benchmarks.sh scenarios
15+
scripts/import-benchmarks.sh scenarios [profile]
1616
scripts/import-benchmarks.sh breakdown
1717
1818
Commands:
1919
table Print the 10/100/1000 import stock-vs-current benchmark table.
2020
scenarios Print the stock-vs-current change-type scenario table.
21+
Optional profiles: local, local-high, external.
2122
breakdown Print a focused 1000-import cold/unchanged breakdown.
2223
EOF
2324
}
@@ -27,7 +28,11 @@ case "${1:-}" in
2728
WIRE_IMPORT_BENCH_TABLE=1 go test ./internal/wire -run TestPrintImportScaleBenchmarkTable -count=1 -v
2829
;;
2930
scenarios)
30-
WIRE_IMPORT_BENCH_SCENARIOS=1 go test ./internal/wire -run TestPrintImportScenarioBenchmarkTable -count=1 -v
31+
if [[ -n "${2:-}" ]]; then
32+
WIRE_IMPORT_BENCH_SCENARIOS=1 WIRE_IMPORT_BENCH_PROFILE="${2}" go test ./internal/wire -run TestPrintImportScenarioBenchmarkTable -count=1 -v
33+
else
34+
WIRE_IMPORT_BENCH_SCENARIOS=1 go test ./internal/wire -run TestPrintImportScenarioBenchmarkTable -count=1 -v
35+
fi
3136
;;
3237
breakdown)
3338
WIRE_IMPORT_BENCH_BREAKDOWN=1 go test ./internal/wire -run TestPrintImportScaleBenchmarkBreakdown -count=1 -v

0 commit comments

Comments
 (0)