async for vs promise.all /w delay
Date tested:
2 years ago
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36
Test name
Executions per second
asyncFor
193887.1 Ops/sec
asyncPromiseAll
67641.3 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
async function asyncFor() { for (const x of [1, 2, 3]) { await new Promise(resolve => setTimeout(() => resolve(x > 0), 500)); } } async function asyncPromiseAll() { await Promise.all([1, 2, 3].map(x => new Promise(resolve => setTimeout(() => resolve(x > 0), 500)) )); }
Tests:
asyncFor
asyncFor()
asyncPromiseAll
asyncPromiseAll()
Open this result on MeasureThat.net