mirror of
https://github.com/nodejs/node.git
synced 2025-05-11 06:49:53 +00:00

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>
30 lines
581 B
JavaScript
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);
|
|
}
|