2016-02-20 02:03:16 +01:00
|
|
|
'use strict';
|
2017-09-14 03:48:53 +02:00
|
|
|
const common = require('../common.js');
|
2017-12-30 03:57:01 +01:00
|
|
|
const { posix } = require('path');
|
2015-06-06 02:43:48 +02:00
|
|
|
|
2017-09-14 03:48:53 +02:00
|
|
|
const bench = common.createBenchmark(main, {
|
2016-02-06 04:23:29 +01:00
|
|
|
paths: [
|
|
|
|
'',
|
|
|
|
['', ''].join('|'),
|
|
|
|
['foo/bar', '/tmp/file/', '..', 'a/../subfile'].join('|'),
|
2019-02-05 07:06:08 +01:00
|
|
|
['a/b/c/', '../../..'].join('|'),
|
2016-02-06 04:23:29 +01:00
|
|
|
],
|
2018-12-30 00:26:36 +01:00
|
|
|
n: [1e5]
|
2015-06-06 02:43:48 +02:00
|
|
|
});
|
|
|
|
|
2017-12-30 03:57:01 +01:00
|
|
|
function main({ n, paths }) {
|
|
|
|
const args = paths.split('|');
|
2018-12-30 00:26:36 +01:00
|
|
|
const copy = [...args];
|
|
|
|
const orig = copy[0];
|
2015-06-06 02:43:48 +02:00
|
|
|
|
|
|
|
bench.start();
|
|
|
|
for (var i = 0; i < n; i++) {
|
2018-12-30 00:26:36 +01:00
|
|
|
if (i % 3 === 0) {
|
|
|
|
copy[0] = `${orig}${i}`;
|
|
|
|
posix.resolve(...copy);
|
|
|
|
} else {
|
|
|
|
posix.resolve(...args);
|
|
|
|
}
|
2015-06-06 02:43:48 +02:00
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
}
|