benchmark: add a warmup on bench-openSync

PR-URL: https://github.com/nodejs/node/pull/57051
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Raz Luvaton <rluvaton@gmail.com>
This commit is contained in:
Elves Vieira 2025-02-16 19:37:42 -01:00 committed by GitHub
parent b6cd6b7e31
commit 610e474728
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,6 +10,18 @@ const bench = common.createBenchmark(main, {
n: [1e5],
});
function runBench({ n, path }) {
for (let i = 0; i < n; i++) {
try {
const fd = fs.openSync(path, 'r', 0o666);
fs.closeSync(fd);
} catch {
// do nothing
}
}
}
function main({ n, type }) {
let path;
@ -24,14 +36,9 @@ function main({ n, type }) {
new Error('Invalid type');
}
runBench({ n, path });
bench.start();
for (let i = 0; i < n; i++) {
try {
const fd = fs.openSync(path, 'r', 0o666);
fs.closeSync(fd);
} catch {
// do nothing
}
}
runBench({ n, path });
bench.end(n);
}