summaryrefslogtreecommitdiff
path: root/benchmark/async_hooks/async-local-storage-run.js
blob: db2a44904f5d13f0ba682dbf1f9bc86f1ee538c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
'use strict';
const common = require('../common.js');
const { AsyncLocalStorage } = require('async_hooks');

const bench = common.createBenchmark(main, {
  n: [1e7],
});

async function run(store, n) {
  for (let i = 0; i < n; i++) {
    await new Promise((resolve) => store.run(i, resolve));
  }
}

function main({ n }) {
  const store = new AsyncLocalStorage();
  bench.start();
  run(store, n).then(() => {
    bench.end(n);
  });
}