Skip to content

Commit 430b4ec

Browse files
authored
fix: run benchmarks sequentially (fix #2004) (#3151)
1 parent 0f86ff9 commit 430b4ec

File tree

1 file changed

+22
-21
lines changed

1 file changed

+22
-21
lines changed

packages/vitest/src/runtime/runners/benchmark.ts

+22-21
Original file line numberDiff line numberDiff line change
@@ -88,30 +88,31 @@ async function runBenchmarkSuite(suite: Suite, runner: VitestRunner) {
8888
})
8989
})
9090

91-
Promise.all(benchmarkGroup.map(async (benchmark) => {
91+
const tasks: BenchTask[] = []
92+
for (const benchmark of benchmarkGroup) {
9293
await benchmark.meta.task!.warmup()
9394
const { setTimeout } = getSafeTimers()
94-
return await new Promise<BenchTask>(resolve => setTimeout(async () => {
95+
tasks.push(await new Promise<BenchTask>(resolve => setTimeout(async () => {
9596
resolve(await benchmark.meta.task!.run())
96-
}))
97-
})).then((tasks) => {
98-
suite.result!.duration = performance.now() - start
99-
suite.result!.state = 'pass'
100-
101-
tasks
102-
.sort((a, b) => a.result!.mean - b.result!.mean)
103-
.forEach((cycle, idx) => {
104-
const benchmark = benchmarkMap[cycle.name || '']
105-
benchmark.result!.state = 'pass'
106-
if (benchmark) {
107-
const result = benchmark.result!.benchmark!
108-
result.rank = Number(idx) + 1
109-
updateTask(benchmark)
110-
}
111-
})
112-
updateTask(suite)
113-
defer.resolve(null)
114-
})
97+
})))
98+
}
99+
100+
suite.result!.duration = performance.now() - start
101+
suite.result!.state = 'pass'
102+
103+
tasks
104+
.sort((a, b) => a.result!.mean - b.result!.mean)
105+
.forEach((cycle, idx) => {
106+
const benchmark = benchmarkMap[cycle.name || '']
107+
benchmark.result!.state = 'pass'
108+
if (benchmark) {
109+
const result = benchmark.result!.benchmark!
110+
result.rank = Number(idx) + 1
111+
updateTask(benchmark)
112+
}
113+
})
114+
updateTask(suite)
115+
defer.resolve(null)
115116

116117
await defer
117118
}

0 commit comments

Comments
 (0)