async for vs promise all (setTimeout version)
Inspired by: https://www.measurethat.net/Benchmarks/Show/13019/0/async-for-vs-promiseall
Date tested:
3 years ago
User agent:
Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36 OPR/79.0.4143.50
Test name
Executions per second
asyncFor
296886.7 Ops/sec
asyncPromiseAll
35007.5 Ops/sec
Benchmark definition (click to collapse):
Script Preparation code:
function emptyTimeout(ms) { return new Promise((resolve, reject) => setTimeout(() => resolve(), ms)); } async function asyncFor() { for (let i = 50; i < 500; i += 50) { await emptyTimeout(i); } } async function asyncPromiseAll() { const promises = []; for (let i = 50; i < 500; i += 50) { promises.push(emptyTimeout(i)); } await Promise.all(promises); }
Tests:
asyncFor
asyncFor()
asyncPromiseAll
asyncPromiseAll()
Open this result on MeasureThat.net