summaryrefslogtreecommitdiff
path: root/deps/node/benchmark/path/relative-posix.js
blob: 2c4dd31d2778c7dd9e300912c72429a5d04026f9 (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
27
28
29
30
31
32
33
34
'use strict';
const common = require('../common.js');
const { posix } = require('path');

const bench = common.createBenchmark(main, {
  paths: [
    ['/data/orandea/test/aaa', '/data/orandea/impl/bbb'].join('|'),
    ['/', '/var'].join('|'),
    ['/', '/'].join('|'),
    ['/var', '/bin'].join('|'),
    ['/foo/bar/baz/quux', '/'].join('|'),
    ['/foo/bar/baz/quux', '/foo/bar/baz/quux'].join('|'),
    ['/foo/bar/baz/quux', '/var/log'].join('|'),
  ],
  n: [1e5]
});

function main({ n, paths }) {
  var to = '';
  const delimIdx = paths.indexOf('|');
  if (delimIdx > -1) {
    to = paths.slice(delimIdx + 1);
    paths = paths.slice(0, delimIdx);
  }

  bench.start();
  for (let i = 0; i < n; i++) {
    if (i % 3 === 0)
      posix.relative(`${paths}${i}`, `${to}${i}`);
    else
      posix.relative(paths, to);
  }
  bench.end(n);
}