Skip to content

Commit

Permalink
benchmark: add a warmup on bench-openSync
Browse files Browse the repository at this point in the history
PR-URL: #57051
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Raz Luvaton <[email protected]>
  • Loading branch information
elvessilvavieira authored and targos committed Feb 17, 2025
1 parent 9de45cb commit f4a82fd
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions benchmark/fs/bench-openSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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);
}

0 comments on commit f4a82fd

Please sign in to comment.