benchmark: add warmup to accessSync bench

PR-URL: https://github.com/nodejs/node/pull/50073
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
This commit is contained in:
Rafael Gonzaga 2023-10-14 16:51:30 -03:00 committed by GitHub
parent 18a818744f
commit 3c0ec61c4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

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