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