2016-08-30 20:52:41 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
const fs = require('fs');
|
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
2023-11-23 08:25:15 +08:00
|
|
|
n: [1e4],
|
2023-02-02 03:16:18 +08:00
|
|
|
statSyncType: ['fstatSync', 'lstatSync', 'statSync'],
|
2016-08-30 20:52:41 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
2017-12-30 10:57:52 +08:00
|
|
|
function main({ n, statSyncType }) {
|
2017-10-07 04:00:46 +08:00
|
|
|
const arg = (statSyncType === 'fstatSync' ?
|
|
|
|
fs.openSync(__filename, 'r') :
|
|
|
|
__dirname);
|
|
|
|
const fn = fs[statSyncType];
|
2017-03-12 08:41:20 +08:00
|
|
|
|
|
|
|
bench.start();
|
2020-01-25 01:12:49 +08:00
|
|
|
for (let i = 0; i < n; i++) {
|
2017-03-12 08:41:20 +08:00
|
|
|
fn(arg);
|
2016-08-30 20:52:41 +08:00
|
|
|
}
|
2017-03-12 08:41:20 +08:00
|
|
|
bench.end(n);
|
|
|
|
|
2020-11-21 09:39:21 +08:00
|
|
|
if (statSyncType === 'fstatSync')
|
2017-03-12 08:41:20 +08:00
|
|
|
fs.closeSync(arg);
|
2016-08-30 20:52:41 +08:00
|
|
|
}
|