Files
node/benchmark/fs/readFileSync.js
Yagiz Nizipli b76862df0a fs: add a fast-path for readFileSync utf-8
PR-URL: https://github.com/nodejs/node/pull/48658
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
2023-07-12 18:37:42 +00:00

25 lines
543 B
JavaScript

'use strict';
const common = require('../common.js');
const fs = require('fs');
const bench = common.createBenchmark(main, {
encoding: ['undefined', 'utf8'],
path: ['existing', 'non-existing'],
n: [60e1],
});
function main({ n, encoding, path }) {
const enc = encoding === 'undefined' ? undefined : encoding;
const file = path === 'existing' ? __filename : '/tmp/not-found';
bench.start();
for (let i = 0; i < n; ++i) {
try {
fs.readFileSync(file, enc);
} catch {
// do nothing
}
}
bench.end(n);
}