summaryrefslogtreecommitdiff
path: root/benchmark/path/relative-win32.js
blob: 81fd10b46c22465ab4eb1339782e95d59228c8be (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 { win32 } = require('path');

const bench = common.createBenchmark(main, {
  paths: [
    ['C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb'].join('|'),
    ['C:\\', 'D:\\'].join('|'),
    ['C:\\foo\\bar\\baz', 'C:\\foo\\bar\\baz'].join('|'),
    ['C:\\foo\\BAR\\BAZ', 'C:\\foo\\bar\\baz'].join('|'),
    ['C:\\foo\\bar\\baz\\quux', 'C:\\'].join('|'),
  ],
  n: [1e6]
});

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

  // Warmup
  for (var i = 0; i < n; i++) {
    win32.relative(paths, to);
  }

  bench.start();
  for (i = 0; i < n; i++) {
    win32.relative(paths, to);
  }
  bench.end(n);
}