For of vs map async (v2)

Revision 2 of this benchmark created on


Setup

const sleep = async (num, time = 1500) => new Promise(resolve => {
    setTimeout(() => {
        resolve(num);
    }, num * time);
});

Test runner

Ready to run.

Testing in
TestOps/sec
Using map with async/await and promises
const arr = [1, 2, 3, 4, 5];

await Promise.all(
  arr.map(async item => sleep(item))
);
ready
Using for of with await
const arr = [1, 2, 3, 4, 5];

for (const e of arr) {
    await sleep(e);
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.