2016-08-30 12:52:41 +00:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
2017-03-12 00:41:20 +00:00
|
|
|
n: [20e4],
|
2023-02-01 19:16:18 +00:00
|
|
|
statType: ['fstat', 'lstat', 'stat'],
|
2016-08-30 12:52:41 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2017-12-30 02:57:52 +00:00
|
|
|
function main({ n, statType }) {
|
2020-01-24 17:12:49 +00:00
|
|
|
let arg;
|
2017-10-06 20:00:46 +00:00
|
|
|
if (statType === 'fstat')
|
2017-03-12 00:41:20 +00:00
|
|
|
arg = fs.openSync(__filename, 'r');
|
|
|
|
else
|
|
|
|
arg = __filename;
|
2016-08-30 12:52:41 +00:00
|
|
|
|
|
|
|
bench.start();
|
|
|
|
(function r(cntr, fn) {
|
2017-03-12 00:41:20 +00:00
|
|
|
if (cntr-- <= 0) {
|
|
|
|
bench.end(n);
|
2017-10-06 20:00:46 +00:00
|
|
|
if (statType === 'fstat')
|
2017-03-12 00:41:20 +00:00
|
|
|
fs.closeSync(arg);
|
|
|
|
return;
|
|
|
|
}
|
2019-02-05 06:06:08 +00:00
|
|
|
fn(arg, () => {
|
2016-08-30 12:52:41 +00:00
|
|
|
r(cntr, fn);
|
|
|
|
});
|
2017-10-06 20:00:46 +00:00
|
|
|
}(n, fs[statType]));
|
2016-08-30 12:52:41 +00:00
|
|
|
}
|