2016-02-19 17:03:16 -08:00
|
|
|
'use strict';
|
2017-09-13 22:48:53 -03:00
|
|
|
const common = require('../common.js');
|
2017-12-30 03:57:01 +01:00
|
|
|
const { posix } = require('path');
|
2016-02-05 22:23:29 -05:00
|
|
|
|
2017-09-13 22:48:53 -03:00
|
|
|
const bench = common.createBenchmark(main, {
|
2016-02-05 22:23:29 -05:00
|
|
|
paths: [
|
|
|
|
['/data/orandea/test/aaa', '/data/orandea/impl/bbb'].join('|'),
|
|
|
|
['/', '/var'].join('|'),
|
|
|
|
['/', '/'].join('|'),
|
|
|
|
['/var', '/bin'].join('|'),
|
|
|
|
['/foo/bar/baz/quux', '/'].join('|'),
|
|
|
|
['/foo/bar/baz/quux', '/foo/bar/baz/quux'].join('|'),
|
2019-02-04 22:06:08 -08:00
|
|
|
['/foo/bar/baz/quux', '/var/log'].join('|'),
|
2016-02-05 22:23:29 -05:00
|
|
|
],
|
2023-02-14 18:09:42 +01:00
|
|
|
n: [1e5],
|
2016-02-05 22:23:29 -05:00
|
|
|
});
|
|
|
|
|
2017-12-30 03:57:01 +01:00
|
|
|
function main({ n, paths }) {
|
2020-01-31 16:50:00 +01:00
|
|
|
let to = '';
|
2017-12-30 03:57:01 +01:00
|
|
|
const delimIdx = paths.indexOf('|');
|
2016-02-05 22:23:29 -05:00
|
|
|
if (delimIdx > -1) {
|
2017-12-30 03:57:01 +01:00
|
|
|
to = paths.slice(delimIdx + 1);
|
|
|
|
paths = paths.slice(0, delimIdx);
|
2016-02-05 22:23:29 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
bench.start();
|
2018-12-30 00:26:36 +01:00
|
|
|
for (let i = 0; i < n; i++) {
|
|
|
|
if (i % 3 === 0)
|
|
|
|
posix.relative(`${paths}${i}`, `${to}${i}`);
|
|
|
|
else
|
|
|
|
posix.relative(paths, to);
|
2016-02-05 22:23:29 -05:00
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
}
|