Skip to content

Commit 3fa841d

Browse files
committed
Group solver profiling by solver name across scenarios, rank by total runtime, and improve sub-1s timing precision
1 parent dbc11da commit 3fa841d

File tree

1 file changed

+36
-33
lines changed

1 file changed

+36
-33
lines changed

scripts/profile-solvers.ts

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ const getPercentile = (values: number[], p: number): number | null => {
135135

136136
const formatTime = (ms: number | null): string => {
137137
if (ms === null) return "n/a"
138-
if (ms < 1000) return `${ms.toFixed(0)}ms`
138+
if (ms < 1000) return `${ms.toFixed(2)}ms`
139139
return `${(ms / 1000).toFixed(2)}s`
140140
}
141141

@@ -205,82 +205,85 @@ const main = () => {
205205
// --- Aggregate by solver name + success/fail ---
206206
// Skip the top-level pipeline solver itself
207207
const records = allRecords.filter(
208-
(r) => r.name !== "AutoroutingPipelineSolver2_PortPointPathing",
208+
(r) => !r.name.startsWith("AutoroutingPipelineSolver"),
209209
)
210210

211-
const groups = new Map<string, SolverRecord[]>()
211+
const groupsByName = new Map<string, SolverRecord[]>()
212212
for (const record of records) {
213-
const key = `${record.name}|${record.success ? "success" : "fail"}`
214-
if (!groups.has(key)) groups.set(key, [])
215-
groups.get(key)!.push(record)
213+
if (!groupsByName.has(record.name)) groupsByName.set(record.name, [])
214+
groupsByName.get(record.name)!.push(record)
216215
}
217216

218217
type Row = {
219218
name: string
220-
status: string
221-
count: number
219+
attemptCount: number
220+
scenarioCount: number
221+
scenarioSuccessRate: number
222222
maxIter: number
223+
totalTimeMs: number
223224
p50Time: number | null
224225
p95Time: number | null
225-
p99Time: number | null
226226
p50Iter: number | null
227227
p95Iter: number | null
228-
p99Iter: number | null
229228
}
230229

231230
const rows: Row[] = []
232-
for (const [key, recs] of groups) {
233-
const [name, status] = key.split("|")
231+
for (const [name, recs] of groupsByName) {
232+
const scenariosTouched = new Set(recs.map((r) => r.scenarioName))
233+
const scenariosWithSuccess = new Set(
234+
recs.filter((r) => r.success).map((r) => r.scenarioName),
235+
)
234236
const times = recs.map((r) => r.timeMs)
235237
const iters = recs.map((r) => r.iterations)
236238
const maxIter = Math.round(Math.max(...recs.map((r) => r.maxIterations)))
239+
const totalTimeMs = recs.reduce((sum, r) => sum + r.timeMs, 0)
237240
rows.push({
238-
name: name!,
239-
status: status!,
240-
count: recs.length,
241+
name,
242+
attemptCount: recs.length,
243+
scenarioCount: scenariosTouched.size,
244+
scenarioSuccessRate:
245+
scenariosTouched.size === 0
246+
? 0
247+
: (scenariosWithSuccess.size / scenariosTouched.size) * 100,
241248
maxIter,
249+
totalTimeMs,
242250
p50Time: getPercentile(times, 0.5),
243251
p95Time: getPercentile(times, 0.95),
244-
p99Time: getPercentile(times, 0.99),
245252
p50Iter: getPercentile(iters, 0.5),
246253
p95Iter: getPercentile(iters, 0.95),
247-
p99Iter: getPercentile(iters, 0.99),
248254
})
249255
}
250256

251-
// Sort by P95 time (slowest first), then solver name, then success before fail
257+
// Sort by total accumulated time (slowest first), then solver name
252258
rows.sort((a, b) => {
253-
const aP95 = a.p95Time ?? Number.NEGATIVE_INFINITY
254-
const bP95 = b.p95Time ?? Number.NEGATIVE_INFINITY
255-
if (aP95 !== bP95) return bP95 - aP95
256-
if (a.name !== b.name) return a.name.localeCompare(b.name)
257-
return a.status === "success" ? -1 : 1
259+
if (a.totalTimeMs !== b.totalTimeMs) return b.totalTimeMs - a.totalTimeMs
260+
return a.name.localeCompare(b.name)
258261
})
259262

260263
const headers = [
261264
"Solver",
262-
"Status",
263-
"N",
265+
"Attempts",
266+
"Scenarios",
267+
"Success %",
264268
"MAX_ITER",
269+
"Total Time",
265270
"P50 Time",
266-
"P50 Iters",
267271
"P95 Time",
272+
"P50 Iters",
268273
"P95 Iters",
269-
"P99 Time",
270-
"P99 Iters",
271274
]
272275

273276
const body = rows.map((r) => [
274277
r.name,
275-
r.status,
276-
String(r.count),
278+
String(r.attemptCount),
279+
String(r.scenarioCount),
280+
`${r.scenarioSuccessRate.toFixed(0)}%`,
277281
String(r.maxIter),
282+
formatTime(r.totalTimeMs),
278283
formatTime(r.p50Time),
279-
formatIter(r.p50Iter),
280284
formatTime(r.p95Time),
285+
formatIter(r.p50Iter),
281286
formatIter(r.p95Iter),
282-
formatTime(r.p99Time),
283-
formatIter(r.p99Iter),
284287
])
285288

286289
const table = formatTable(headers, body)

0 commit comments

Comments
 (0)