• 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  pathext: [
7    '',
8    'C:\\',
9    'C:\\foo',
10    'D:\\foo\\.bar.baz',
11    ['E:\\foo\\.bar.baz', '.baz'].join('|'),
12    'foo',
13    'foo\\bar.',
14    ['foo\\bar.', '.'].join('|'),
15    '\\foo\\bar\\baz\\asdf\\quux.html',
16    ['\\foo\\bar\\baz\\asdf\\quux.html', '.html'].join('|'),
17  ],
18  n: [1e5]
19});
20
21function main({ n, pathext }) {
22  let ext;
23  const extIdx = pathext.indexOf('|');
24  if (extIdx !== -1) {
25    ext = pathext.slice(extIdx + 1);
26    pathext = pathext.slice(0, extIdx);
27  }
28
29  bench.start();
30  for (let i = 0; i < n; i++) {
31    win32.basename(i % 3 === 0 ? `${pathext}${i}` : pathext, ext);
32  }
33  bench.end(n);
34}
35