Skip to content

Commit cfdff8c

Browse files
committed
Enhance benchmark reporting by adding total duration and pass count metrics
1 parent feea856 commit cfdff8c

File tree

3 files changed

+48
-6
lines changed

3 files changed

+48
-6
lines changed

scripts/highdensity-benchmark/index.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ import { parseArgs } from "node:util"
44
import { availableParallelism } from "node:os"
55
import { calculateMse } from "./metrics/calculateMse.ts"
66
import { runBenchmarkWithWorkers } from "./runBenchmarkWithWorkers/index.ts"
7+
import { formatSeconds } from "./runBenchmarkWithWorkers/shared.ts"
78
import { NodeWithPortPoints } from "lib/types/high-density-types.ts"
89

910
type CliOptions = {
1011
concurrency: number
1112
timeoutSeconds: number
1213
}
1314

15+
const formatPercent = (value: number) => `${(value * 100).toFixed(1)}%`
16+
1417
const usage = () =>
1518
[
1619
"Usage: bun scripts/highdensity-benchmark/index.ts [options]",
@@ -82,10 +85,18 @@ const main = async ({ concurrency, timeoutSeconds }: CliOptions) => {
8285
concurrency,
8386
timeoutMs: timeoutSeconds * 1000,
8487
})
88+
const completedCount = completedScores.results.length
89+
const passRate =
90+
completedCount === 0 ? 0 : completedScores.passCount / completedCount
8591

8692
// Avoid a divide-by-zero MSE when every single problem times out.
87-
if (completedScores.results.length === 0) {
93+
if (completedCount === 0) {
94+
console.log(
95+
"Total duration:",
96+
`${formatSeconds(completedScores.totalDurationMs)} seconds`,
97+
)
8898
console.log("Completed problems: 0")
99+
console.log("Pass rate: 0.0% (0/0)")
89100
console.log(
90101
"Timed out problems:",
91102
completedScores.timedOutProblemIds.length,
@@ -95,7 +106,15 @@ const main = async ({ concurrency, timeoutSeconds }: CliOptions) => {
95106
}
96107

97108
const mse = calculateMse(completedScores.results)
98-
console.log("Completed problems:", completedScores.results.length)
109+
console.log(
110+
"Total duration:",
111+
`${formatSeconds(completedScores.totalDurationMs)} seconds`,
112+
)
113+
console.log("Completed problems:", completedCount)
114+
console.log(
115+
"Pass rate:",
116+
`${formatPercent(passRate)} (${completedScores.passCount}/${completedCount})`,
117+
)
99118
console.log("Timed out problems:", completedScores.timedOutProblemIds.length)
100119
console.log("Mean Squared Error:", mse)
101120
}

scripts/highdensity-benchmark/runBenchmarkWithWorkers/BenchmarkWorkerPool.ts

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import {
33
BenchmarkTask,
44
RunBenchmarkOptions,
55
RunBenchmarkResult,
6-
formatSeconds,
76
getProblemId,
87
} from "./shared.ts"
98

@@ -13,6 +12,7 @@ export class BenchmarkWorkerPool {
1312
private readonly timeoutMs: number
1413
private readonly results: number[] = []
1514
private readonly timedOutProblemIds: string[] = []
15+
private passCount = 0
1616
private completedProblems = 0
1717
private nextTaskIndex = 0
1818
private nextTaskId = 1
@@ -45,13 +45,17 @@ export class BenchmarkWorkerPool {
4545
return {
4646
results: [],
4747
timedOutProblemIds: [],
48+
totalDurationMs: 0,
49+
passCount: 0,
4850
}
4951
}
5052

5153
console.log(
5254
`Starting high-density benchmark with ${this.workers.length} workers across ${this.tasks.length} cases`,
5355
)
5456

57+
const startedAt = Date.now()
58+
5559
try {
5660
await this.runWorkers()
5761
} finally {
@@ -61,6 +65,8 @@ export class BenchmarkWorkerPool {
6165
return {
6266
results: this.results,
6367
timedOutProblemIds: this.timedOutProblemIds,
68+
totalDurationMs: Date.now() - startedAt,
69+
passCount: this.passCount,
6470
}
6571
}
6672

@@ -76,14 +82,16 @@ export class BenchmarkWorkerPool {
7682
)
7783
if (result === null) {
7884
this.timedOutProblemIds.push(task.problemId)
85+
this.logProgress()
7986
continue
8087
}
8188

8289
this.completedProblems += 1
83-
console.log(
84-
`${task.problemId} ${result.solved ? "pass" : "fail"} solve in ${formatSeconds(result.solveDurationMs)} seconds (${this.completedProblems}/${this.tasks.length})`,
85-
)
90+
if (result.solved) {
91+
this.passCount += 1
92+
}
8693
this.results.push(result.value)
94+
this.logProgress()
8795
}
8896
}
8997

@@ -110,4 +118,17 @@ export class BenchmarkWorkerPool {
110118
this.nextTaskIndex += 1
111119
return task
112120
}
121+
122+
private logProgress() {
123+
const processedProblems =
124+
this.completedProblems + this.timedOutProblemIds.length
125+
const completedRatio =
126+
this.completedProblems === 0 ? 0 : this.passCount / this.completedProblems
127+
128+
console.log(
129+
`Progress ${processedProblems}/${this.tasks.length} | pass ${(
130+
completedRatio * 100
131+
).toFixed(1)}%`,
132+
)
133+
}
113134
}

scripts/highdensity-benchmark/runBenchmarkWithWorkers/shared.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ export type RunBenchmarkOptions = {
4040
export type RunBenchmarkResult = {
4141
results: number[]
4242
timedOutProblemIds: string[]
43+
totalDurationMs: number
44+
passCount: number
4345
}
4446

4547
export const getProblemId = (problem: NodeWithPortPoints, index: number) => {

0 commit comments

Comments
 (0)