2018-01-22 02:21:25 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
2018-05-04 02:40:48 +08:00
|
|
|
const fsPromises = require('fs').promises;
|
2018-01-22 02:21:25 +08:00
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
|
|
|
n: [20e4],
|
|
|
|
statType: ['fstat', 'lstat', 'stat']
|
|
|
|
});
|
|
|
|
|
|
|
|
async function run(n, statType) {
|
|
|
|
const arg = statType === 'fstat' ?
|
2018-02-14 17:04:22 +08:00
|
|
|
await fsPromises.open(__filename, 'r') : __filename;
|
2018-01-22 02:21:25 +08:00
|
|
|
let remaining = n;
|
|
|
|
bench.start();
|
|
|
|
while (remaining-- > 0)
|
2018-02-14 17:04:22 +08:00
|
|
|
await fsPromises[statType](arg);
|
2018-01-22 02:21:25 +08:00
|
|
|
bench.end(n);
|
|
|
|
|
|
|
|
if (typeof arg.close === 'function')
|
|
|
|
await arg.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
function main(conf) {
|
|
|
|
const n = conf.n >>> 0;
|
|
|
|
const statType = conf.statType;
|
|
|
|
run(n, statType).catch(console.log);
|
|
|
|
}
|