2016-02-20 02:03:16 +01:00
|
|
|
'use strict';
|
2017-09-14 03:48:53 +02:00
|
|
|
const common = require('../common.js');
|
|
|
|
const path = require('path');
|
2016-02-06 04:23:29 +01:00
|
|
|
|
2017-09-14 03:48:53 +02:00
|
|
|
const bench = common.createBenchmark(main, {
|
2016-02-06 04:23:29 +01:00
|
|
|
pathext: [
|
|
|
|
'',
|
|
|
|
'/',
|
|
|
|
'/foo',
|
|
|
|
'/foo/.bar.baz',
|
|
|
|
['/foo/.bar.baz', '.baz'].join('|'),
|
|
|
|
'foo',
|
|
|
|
'foo/bar.',
|
|
|
|
['foo/bar.', '.'].join('|'),
|
|
|
|
'/foo/bar/baz/asdf/quux.html',
|
|
|
|
['/foo/bar/baz/asdf/quux.html', '.html'].join('|')
|
|
|
|
],
|
|
|
|
n: [1e6]
|
|
|
|
});
|
|
|
|
|
|
|
|
function main(conf) {
|
2017-09-14 03:48:53 +02:00
|
|
|
const n = +conf.n;
|
|
|
|
const p = path.posix;
|
2017-04-17 03:01:12 +02:00
|
|
|
var input = String(conf.pathext);
|
2016-02-06 04:23:29 +01:00
|
|
|
var ext;
|
2017-09-14 03:48:53 +02:00
|
|
|
const extIdx = input.indexOf('|');
|
2016-02-06 04:23:29 +01:00
|
|
|
if (extIdx !== -1) {
|
|
|
|
ext = input.slice(extIdx + 1);
|
|
|
|
input = input.slice(0, extIdx);
|
|
|
|
}
|
|
|
|
|
|
|
|
bench.start();
|
|
|
|
for (var i = 0; i < n; i++) {
|
|
|
|
p.basename(input, ext);
|
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
}
|