-
Notifications
You must be signed in to change notification settings - Fork 36
Expand file tree
/
Copy pathbenchmark.sh
More file actions
executable file
·194 lines (167 loc) · 5.32 KB
/
benchmark.sh
File metadata and controls
executable file
·194 lines (167 loc) · 5.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
#!/usr/bin/env bash
set -euo pipefail
SOLVER_NAME=""
SCENARIO_LIMIT=""
EFFORT=""
SAMPLE_TIMEOUT=""
INCLUDE_ASSIGNABLE=false
DATASET="dataset01"
DEFAULT_SOLVER_NAME="AutoroutingPipelineSolver4"
PIPELINE_ID=""
resolve_pipeline_solver_name() {
case "$1" in
1) echo "AutoroutingPipeline1_OriginalUnravel" ;;
2) echo "AutoroutingPipelineSolver2_PortPointPathing" ;;
3) echo "AutoroutingPipelineSolver3_HgPortPointPathing" ;;
4) echo "AutoroutingPipelineSolver4" ;;
*)
echo "Unknown pipeline: $1" >&2
exit 1
;;
esac
}
default_concurrency() {
getconf _NPROCESSORS_ONLN 2>/dev/null || nproc 2>/dev/null || echo 4
}
CONCURRENCY="${BENCHMARK_CONCURRENCY:-$(default_concurrency)}"
get_solvers() {
INCLUDE_ASSIGNABLE="$INCLUDE_ASSIGNABLE" bun --eval '
import { readFileSync } from "node:fs"
import { join } from "node:path"
// Use autorouter-pipelines/index.ts as the source of truth for benchmarkable solvers
const pipelinesIndex = readFileSync(join(process.cwd(), "lib", "autorouter-pipelines", "index.ts"), "utf8")
const pipelineNames = [...pipelinesIndex.matchAll(/export\s*\{\s*(\w+)\s*\}/g)].map(m => m[1])
// Resolve aliases from lib/index.ts
const libIndex = readFileSync(join(process.cwd(), "lib", "index.ts"), "utf8")
const solvers = pipelineNames.map(name => {
const aliasMatch = libIndex.match(new RegExp(name + "\\s+as\\s+(\\w+)"))
return aliasMatch ? aliasMatch[1] : name
})
const includeAssignable = process.env.INCLUDE_ASSIGNABLE === "true"
const filtered = includeAssignable ? solvers : solvers.filter(name => !name.includes("Assignable"))
console.log(filtered.join("\n"))
' 2>/dev/null || true
}
print_help() {
cat <<'EOF'
Usage:
./benchmark.sh [solver-name|all] [scenario-limit] [--concurrency N] [--effort N] [--sample-timeout DURATION] [--dataset NAME] [--include-assignable]
./benchmark.sh [--solver NAME] [--pipeline N] [--scenario-limit N] [--concurrency N] [--effort N] [--sample-timeout DURATION] [--dataset NAME] [--include-assignable]
Options:
--solver NAME Run only one solver (same as first positional arg)
--pipeline N Run a numbered pipeline alias (1-4)
--scenario-limit N Run only first N scenarios (same as second positional arg)
--concurrency N Number of Bun workers used per solver, or "auto"
--effort N Override scenario effort multiplier
--sample-timeout D Override per-sample timeout directly; otherwise timeout is 60s + 60s * effort
--dataset NAME Dataset to benchmark: dataset01 (default), zdwiel, or srj05
--include-assignable Include assignable pipelines (excluded by default)
-h, --help Show this help
Defaults:
Running ./benchmark.sh with no parameters benchmarks only AutoroutingPipelineSolver4.
Use "all" to benchmark every available solver.
Examples:
./benchmark.sh
./benchmark.sh AutoroutingPipelineSolver4
./benchmark.sh all 20 --concurrency auto
./benchmark.sh --solver AutoroutingPipelineSolver4 --effort 2
./benchmark.sh --solver AutoroutingPipelineSolver4 --sample-timeout 90s
./benchmark.sh --solver AutoroutingPipelineSolver4 --scenario-limit 20
./benchmark.sh --solver AutoroutingPipelineSolver4 --dataset zdwiel --scenario-limit 20
./benchmark.sh --pipeline 4
./benchmark.sh --solver AutoroutingPipelineSolver4 --dataset srj05 --scenario-limit 20
./benchmark.sh --include-assignable
EOF
SOLVERS="$(get_solvers)"
if [ -n "$SOLVERS" ]; then
echo ""
echo "Available solvers:"
while IFS= read -r solver; do
[ -n "$solver" ] && echo " - $solver"
done <<EOF
$SOLVERS
EOF
fi
}
if [ "${1:-}" != "" ] && [[ "${1}" != --* ]]; then
SOLVER_NAME="$1"
shift
fi
if [ "${1:-}" != "" ] && [[ "${1}" != --* ]]; then
SCENARIO_LIMIT="$1"
shift
fi
while [ "$#" -gt 0 ]; do
case "$1" in
-h|--help)
print_help
exit 0
;;
--solver)
SOLVER_NAME="${2:-}"
shift 2
;;
--pipeline)
PIPELINE_ID="${2:-}"
shift 2
;;
--scenario-limit)
SCENARIO_LIMIT="${2:-}"
shift 2
;;
--concurrency)
CONCURRENCY="${2:-}"
if [ "$CONCURRENCY" = "auto" ]; then
CONCURRENCY="$(default_concurrency)"
fi
shift 2
;;
--effort)
EFFORT="${2:-}"
shift 2
;;
--sample-timeout)
SAMPLE_TIMEOUT="${2:-}"
shift 2
;;
--dataset)
DATASET="${2:-}"
shift 2
;;
--include-assignable)
INCLUDE_ASSIGNABLE=true
shift
;;
*)
echo "Unknown argument: $1"
echo "Run ./benchmark.sh --help for usage"
exit 1
;;
esac
done
if [ -n "$PIPELINE_ID" ]; then
SOLVER_NAME="$(resolve_pipeline_solver_name "$PIPELINE_ID")"
fi
CMD=(bun "scripts/benchmark/index.ts" "--concurrency" "$CONCURRENCY")
if [ -z "$SOLVER_NAME" ]; then
SOLVER_NAME="$DEFAULT_SOLVER_NAME"
fi
if [ -n "$SOLVER_NAME" ] && [ "$SOLVER_NAME" != "_" ] && [ "$SOLVER_NAME" != "all" ]; then
CMD+=("--solver" "$SOLVER_NAME")
fi
if [ -n "$SCENARIO_LIMIT" ]; then
CMD+=("--scenario-limit" "$SCENARIO_LIMIT")
fi
if [ -n "$EFFORT" ]; then
CMD+=("--effort" "$EFFORT")
fi
if [ -n "$SAMPLE_TIMEOUT" ]; then
CMD+=("--sample-timeout" "$SAMPLE_TIMEOUT")
fi
if [ -n "$DATASET" ]; then
CMD+=("--dataset" "$DATASET")
fi
if [ "$INCLUDE_ASSIGNABLE" != true ]; then
CMD+=("--exclude-assignable")
fi
"${CMD[@]}"