aboutsummaryrefslogtreecommitdiff
path: root/bench/snippets/async-overhead.mjs
blob: bec278b56158a3064b9363e72db9d4f87443fea3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { bench, run } from "../node_modules/mitata/src/cli.mjs";

bench("noop", function () {});
bench("async function(){}", async function () {});
bench("await 1", async function () {
  return await 1;
});

function callnextTick(resolve) {
  process.nextTick(resolve);
}

function awaitNextTick() {
  return new Promise(callnextTick);
}

bench("promise.nextTick", async function () {
  return awaitNextTick();
});

bench("await new Promise(resolve => resolve())", async function () {
  await new Promise((resolve) => resolve());
});
bench(
  "Promise.all(Array.from({length: 100}, () => new Promise((resolve) => resolve())))",
  async function () {
    return Promise.all(Array.from({ length: 100 }, () => Promise.resolve(1)));
  },
);

await run();