• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const fsPromises = require('fs').promises;
5
6const bench = common.createBenchmark(main, {
7  n: [20e4],
8  statType: ['fstat', 'lstat', 'stat']
9});
10
11async function run(n, statType) {
12  const handleMode = statType === 'fstat';
13  const arg = handleMode ? await fsPromises.open(__filename, 'r') : __filename;
14  let remaining = n;
15  bench.start();
16  while (remaining-- > 0)
17    await (handleMode ? arg.stat() : fsPromises[statType](arg));
18  bench.end(n);
19
20  if (typeof arg.close === 'function')
21    await arg.close();
22}
23
24function main(conf) {
25  const n = conf.n >>> 0;
26  const statType = conf.statType;
27  run(n, statType).catch(console.log);
28}
29