node/benchmark/fs/bench-statSync-failure.js
Rich Trott 776d0b4e62 benchmark: enable no-empty ESLint rule
PR-URL: https://github.com/nodejs/node/pull/41831
Refs: https://eslint.org/docs/rules/no-empty
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
2022-02-05 12:58:27 +00:00

30 lines
581 B
JavaScript

'use strict';
const common = require('../common');
const fs = require('fs');
const path = require('path');
const bench = common.createBenchmark(main, {
n: [1e6],
statSyncType: ['throw', 'noThrow']
});
function main({ n, statSyncType }) {
const arg = path.join(__dirname, 'non.existent');
bench.start();
for (let i = 0; i < n; i++) {
if (statSyncType === 'noThrow') {
fs.statSync(arg, { throwIfNoEntry: false });
} else {
try {
fs.statSync(arg);
} catch {
// Continue regardless of error.
}
}
}
bench.end(n);
}