2016-02-20 09:03:16 +08:00
|
|
|
'use strict';
|
2017-09-14 09:48:53 +08:00
|
|
|
const common = require('../common.js');
|
2017-12-30 10:57:01 +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
|
|
|
paths: [
|
|
|
|
['C:\\orandea\\test\\aaa', 'C:\\orandea\\impl\\bbb'].join('|'),
|
|
|
|
['C:\\', 'D:\\'].join('|'),
|
|
|
|
['C:\\foo\\bar\\baz', 'C:\\foo\\bar\\baz'].join('|'),
|
|
|
|
['C:\\foo\\BAR\\BAZ', 'C:\\foo\\bar\\baz'].join('|'),
|
2019-02-05 14:06:08 +08:00
|
|
|
['C:\\foo\\bar\\baz\\quux', 'C:\\'].join('|'),
|
2016-02-06 11:23:29 +08:00
|
|
|
],
|
|
|
|
n: [1e6]
|
|
|
|
});
|
|
|
|
|
2017-12-30 10:57:01 +08:00
|
|
|
function main({ n, paths }) {
|
2016-02-06 11:23:29 +08:00
|
|
|
var to = '';
|
2017-12-30 10:57:01 +08:00
|
|
|
const delimIdx = paths.indexOf('|');
|
2016-02-06 11:23:29 +08:00
|
|
|
if (delimIdx > -1) {
|
2017-12-30 10:57:01 +08:00
|
|
|
to = paths.slice(delimIdx + 1);
|
|
|
|
paths = paths.slice(0, delimIdx);
|
2016-02-06 11:23:29 +08:00
|
|
|
}
|
|
|
|
|
2017-03-01 19:37:12 +08:00
|
|
|
// Warmup
|
|
|
|
for (var i = 0; i < n; i++) {
|
2017-12-30 10:57:01 +08:00
|
|
|
win32.relative(paths, to);
|
2017-03-01 19:37:12 +08:00
|
|
|
}
|
2016-02-06 11:23:29 +08:00
|
|
|
|
|
|
|
bench.start();
|
2017-03-01 19:37:12 +08:00
|
|
|
for (i = 0; i < n; i++) {
|
2017-12-30 10:57:01 +08:00
|
|
|
win32.relative(paths, to);
|
2016-02-06 11:23:29 +08:00
|
|
|
}
|
|
|
|
bench.end(n);
|
|
|
|
}
|