asyncAwait test

Benchmark created on


Setup

const createAsyncFuction = (timeout) => {
  return () =>
    new Promise((resolve) => {
      setTimeout(() => {
        resolve(`Resolve after ${timeout}ms`);
      }, timeout);
    });
};

const af1 = createAsyncFuction(1000);
const af2 = createAsyncFuction(2000);
const af3 = createAsyncFuction(3000);

Test runner

Ready to run.

Testing in
TestOps/sec
notSoOptimised
async function notSoOptimised() {
  /* Since await is used on every async funtion call, JS endgine waits for it to complete */
  await af1();
  await af2();
  await af3();
  return "done";
}
notSoOptimised();
ready
someWhatOptimised
async function someWhatOptimised() {
  const ref1 = af1();
  const ref2 = af2();
  const ref3 = af3();
  /* Here, first all the async call are triggered then we are awaiting for all to complete */
  await Promise.all([ref1, ref2, ref3]);
  return "done";
}
someWhatOptimised()
ready

Revisions

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