2016-02-20 09:03:16 +08:00
|
|
|
'use strict';
|
2017-09-14 09:48:53 +08:00
|
|
|
const common = require('../common.js');
|
2018-01-23 20:14:21 +08:00
|
|
|
const { win32 } = require('path');
|
2016-02-06 11:23:29 +08:00
|
|
|
|
2017-09-14 09:48:53 +08:00
|
|
|
const bench = common.createBenchmark(main, {
|
2016-02-06 11:23:29 +08:00
|
|
|
pathext: [
|
|
|
|
'',
|
|
|
|
'C:\\',
|
|
|
|
'C:\\foo',
|
|
|
|
'D:\\foo\\.bar.baz',
|
2016-02-25 14:30:10 +08:00
|
|
|
['E:\\foo\\.bar.baz', '.baz'].join('|'),
|
2016-02-06 11:23:29 +08:00
|
|
|
'foo',
|
|
|
|
'foo\\bar.',
|
|
|
|
['foo\\bar.', '.'].join('|'),
|
|
|
|
'\\foo\\bar\\baz\\asdf\\quux.html',
|
2019-02-05 14:06:08 +08:00
|
|
|
['\\foo\\bar\\baz\\asdf\\quux.html', '.html'].join('|'),
|
2016-02-06 11:23:29 +08:00
|
|
|
],
|
2023-02-15 01:09:42 +08:00
|
|
|
n: [1e5],
|
2016-02-06 11:23:29 +08:00
|
|
|
});
|
|
|
|
|
2017-12-30 10:57:01 +08:00
|
|
|
function main({ n, pathext }) {
|
2020-01-31 23:50:00 +08:00
|
|
|
let ext;
|
2017-12-30 10:57:01 +08:00
|
|
|
const extIdx = pathext.indexOf('|');
|
2016-02-06 11:23:29 +08:00
|
|
|
if (extIdx !== -1) {
|
2017-12-30 10:57:01 +08:00
|
|
|
ext = pathext.slice(extIdx + 1);
|
|
|
|
pathext = pathext.slice(0, extIdx);
|
2016-02-06 11:23:29 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
bench.start();
|
2019-07-31 21:26:38 +08:00
|
|
|
for (let i = 0; i < n; i++) {
|
2018-12-30 07:26:36 +08:00
|
|
|
win32.basename(i % 3 === 0 ? `${pathext}${i}` : pathext, ext);
|
2016-02-06 11:23:29 +08:00
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
}
|