Skip to content

Commit

Permalink
benchmark: add warmup to accessSync bench
Browse files Browse the repository at this point in the history
PR-URL: #50073
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
  • Loading branch information
RafaelGSS authored and targos committed Nov 11, 2023
1 parent 06aa4b9 commit 2326971
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 2326971

Please sign in to comment.