Skip to content

Commit

Permalink
fix: run benchmarks sequentially (fix #2004) (#3151)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecodrr committed Apr 8, 2023
1 parent 0f86ff9 commit 430b4ec
Showing 1 changed file with 22 additions and 21 deletions.
43 changes: 22 additions & 21 deletions packages/vitest/src/runtime/runners/benchmark.ts
Expand Up @@ -88,30 +88,31 @@ async function runBenchmarkSuite(suite: Suite, runner: VitestRunner) {
})
})

Promise.all(benchmarkGroup.map(async (benchmark) => {
const tasks: BenchTask[] = []
for (const benchmark of benchmarkGroup) {
await benchmark.meta.task!.warmup()
const { setTimeout } = getSafeTimers()
return await new Promise<BenchTask>(resolve => setTimeout(async () => {
tasks.push(await new Promise<BenchTask>(resolve => setTimeout(async () => {
resolve(await benchmark.meta.task!.run())
}))
})).then((tasks) => {
suite.result!.duration = performance.now() - start
suite.result!.state = 'pass'

tasks
.sort((a, b) => a.result!.mean - b.result!.mean)
.forEach((cycle, idx) => {
const benchmark = benchmarkMap[cycle.name || '']
benchmark.result!.state = 'pass'
if (benchmark) {
const result = benchmark.result!.benchmark!
result.rank = Number(idx) + 1
updateTask(benchmark)
}
})
updateTask(suite)
defer.resolve(null)
})
})))
}

suite.result!.duration = performance.now() - start
suite.result!.state = 'pass'

tasks
.sort((a, b) => a.result!.mean - b.result!.mean)
.forEach((cycle, idx) => {
const benchmark = benchmarkMap[cycle.name || '']
benchmark.result!.state = 'pass'
if (benchmark) {
const result = benchmark.result!.benchmark!
result.rank = Number(idx) + 1
updateTask(benchmark)
}
})
updateTask(suite)
defer.resolve(null)

await defer
}
Expand Down

0 comments on commit 430b4ec

Please sign in to comment.