Skip to content

Commit

Permalink
benchmark: add warmup to accessSync bench
Browse files Browse the repository at this point in the history
PR-URL: nodejs#50073
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
  • Loading branch information
RafaelGSS committed Oct 14, 2023
1 parent 18a8187 commit 3c0ec61
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions benchmark/fs/bench-accessSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,16 @@ const bench = common.createBenchmark(main, {
n: [1e5],
});

function runBench(n, path) {
for (let i = 0; i < n; i++) {
try {
fs.accessSync(path);
} catch {
// do nothing
}
}
}

function main({ n, type }) {
let path;

Expand All @@ -29,14 +39,10 @@ function main({ n, type }) {
default:
new Error('Invalid type');
}
// warmup
runBench(n, path);

bench.start();
for (let i = 0; i < n; i++) {
try {
fs.accessSync(path);
} catch {
// do nothing
}
}
runBench(n, path);
bench.end(n);
}

0 comments on commit 3c0ec61

Please sign in to comment.