Compare async iteration on nested & flat arrays

Benchmark created on


Setup

function processAsync(item) {
  return new Promise(function(resolve) {
    setTimeout(
      resolve,
      Math.random() * 1000
    );
  });
}

const nestedArr = [["a", "b", "c"], ["d", "e", "f"], ["g", "h", "i"]];
const flatArr = ["a", "b", "c", "d", "e", "f", "g", "h", "i"];

Test runner

Ready to run.

Testing in
TestOps/sec
2D array with nested loop
Promise.all(nestedArr.map(arr => {
  return Promise.all(arr.map(processAsync));
})).then(data => {
  console.log(data);
});
ready
flattened array with loop
Promise.all(flatArr.map(processAsync)).then(data => {
	console.log(data);
})
ready

Revisions

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