aboutsummaryrefslogtreecommitdiff
path: root/bench/snippets/async-overhead.mjs
blob: 7af987bff0c54ac42bacf15523edcd0160effa6f (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
import { bench, run } from "mitata";

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();