summaryrefslogtreecommitdiff
path: root/benchmark/fs/bench-statSync.js
blob: 57e03df3b04951c2d76c3c2e1298c575cc369349 (plain)
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
'use strict';

const common = require('../common');
const fs = require('fs');

const bench = common.createBenchmark(main, {
  n: [1e6],
  kind: ['fstatSync', 'lstatSync', 'statSync']
});


function main(conf) {
  const n = conf.n >>> 0;
  const kind = conf.kind;
  const arg = (kind === 'fstatSync' ? fs.openSync(__filename, 'r') : __dirname);
  const fn = fs[conf.kind];

  bench.start();
  for (var i = 0; i < n; i++) {
    fn(arg);
  }
  bench.end(n);

  if (kind === 'fstat')
    fs.closeSync(arg);
}