• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4const fs = require('fs');
5const path = require('path');
6const resolved_path = path.resolve(__dirname, '../../lib/');
7const relative_path = path.relative(__dirname, '../../lib/');
8
9const bench = common.createBenchmark(main, {
10  n: [1e4],
11  pathType: ['relative', 'resolved'],
12});
13
14
15function main({ n, pathType }) {
16  bench.start();
17  if (pathType === 'relative')
18    relativePath(n);
19  else
20    resolvedPath(n);
21}
22
23function relativePath(n) {
24  (function r(cntr) {
25    if (cntr-- <= 0)
26      return bench.end(n);
27    fs.realpath(relative_path, () => {
28      r(cntr);
29    });
30  }(n));
31}
32
33function resolvedPath(n) {
34  (function r(cntr) {
35    if (cntr-- <= 0)
36      return bench.end(n);
37    fs.realpath(resolved_path, () => {
38      r(cntr);
39    });
40  }(n));
41}
42