mirror of
https://github.com/nodejs/node.git
synced 2025-05-09 19:38:23 +00:00

Fix a off-by-one error that made the benchmarks for asynchronous functions run `n - 1` times instead of `n` times. PR-URL: https://github.com/nodejs/node/pull/8338 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
47 lines
931 B
JavaScript
47 lines
931 B
JavaScript
'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],
|
|
type: ['relative', 'resolved'],
|
|
});
|
|
|
|
|
|
function main(conf) {
|
|
const n = conf.n >>> 0;
|
|
const type = conf.type;
|
|
|
|
bench.start();
|
|
if (type === 'relative')
|
|
relativePath(n);
|
|
else if (type === 'resolved')
|
|
resolvedPath(n);
|
|
else
|
|
throw new Error('unknown "type": ' + type);
|
|
}
|
|
|
|
function relativePath(n) {
|
|
(function r(cntr) {
|
|
if (cntr-- <= 0)
|
|
return bench.end(n);
|
|
fs.realpath(relative_path, function() {
|
|
r(cntr);
|
|
});
|
|
}(n));
|
|
}
|
|
|
|
function resolvedPath(n) {
|
|
(function r(cntr) {
|
|
if (cntr-- <= 0)
|
|
return bench.end(n);
|
|
fs.realpath(resolved_path, function() {
|
|
r(cntr);
|
|
});
|
|
}(n));
|
|
}
|