2016-07-14 19:57:26 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const fs = require('fs');
|
|
|
|
const path = require('path');
|
|
|
|
const resolved_path = path.resolve(__dirname, '../../lib/');
|
|
|
|
const relative_path = path.relative(__dirname, '../../lib/');
|
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
|
|
n: [1e4],
|
2017-10-06 22:00:46 +02:00
|
|
|
pathType: ['relative', 'resolved'],
|
2016-07-14 19:57:26 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
function main(conf) {
|
|
|
|
const n = conf.n >>> 0;
|
2017-10-06 22:00:46 +02:00
|
|
|
const pathType = conf.pathType;
|
2016-07-14 19:57:26 +02:00
|
|
|
|
|
|
|
bench.start();
|
2017-10-06 22:00:46 +02:00
|
|
|
if (pathType === 'relative')
|
2016-07-14 19:57:26 +02:00
|
|
|
relativePath(n);
|
2017-10-06 22:00:46 +02:00
|
|
|
else if (pathType === 'resolved')
|
2016-07-14 19:57:26 +02:00
|
|
|
resolvedPath(n);
|
|
|
|
else
|
2017-10-06 22:00:46 +02:00
|
|
|
throw new Error(`unknown "pathType": ${pathType}`);
|
2016-07-14 19:57:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function relativePath(n) {
|
|
|
|
(function r(cntr) {
|
2016-08-30 17:16:09 +02:00
|
|
|
if (cntr-- <= 0)
|
2016-07-14 19:57:26 +02:00
|
|
|
return bench.end(n);
|
|
|
|
fs.realpath(relative_path, function() {
|
|
|
|
r(cntr);
|
|
|
|
});
|
|
|
|
}(n));
|
|
|
|
}
|
|
|
|
|
|
|
|
function resolvedPath(n) {
|
|
|
|
(function r(cntr) {
|
2016-08-30 17:16:09 +02:00
|
|
|
if (cntr-- <= 0)
|
2016-07-14 19:57:26 +02:00
|
|
|
return bench.end(n);
|
|
|
|
fs.realpath(resolved_path, function() {
|
|
|
|
r(cntr);
|
|
|
|
});
|
|
|
|
}(n));
|
|
|
|
}
|