• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common.js');
3const { win32 } = require('path');
4
5const bench = common.createBenchmark(main, {
6  paths: [
7    ['C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb'].join('|'),
8    ['C:\\', 'D:\\'].join('|'),
9    ['C:\\foo\\bar\\baz', 'C:\\foo\\bar\\baz'].join('|'),
10    ['C:\\foo\\BAR\\BAZ', 'C:\\foo\\bar\\baz'].join('|'),
11    ['C:\\foo\\bar\\baz\\quux', 'C:\\'].join('|'),
12  ],
13  n: [1e5]
14});
15
16function main({ n, paths }) {
17  let to = '';
18  const delimIdx = paths.indexOf('|');
19  if (delimIdx > -1) {
20    to = paths.slice(delimIdx + 1);
21    paths = paths.slice(0, delimIdx);
22  }
23
24  bench.start();
25  for (let i = 0; i < n; i++) {
26    if (i % 3 === 0)
27      win32.relative(`${paths}${i}`, `${to}${i}`);
28    else
29      win32.relative(paths, to);
30  }
31  bench.end(n);
32}
33