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:
parent
18a818744f
commit
3c0ec61c4b
@ -13,6 +13,16 @@ const bench = common.createBenchmark(main, {
|
|||||||
n: [1e5],
|
n: [1e5],
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function runBench(n, path) {
|
||||||
|
for (let i = 0; i < n; i++) {
|
||||||
|
try {
|
||||||
|
fs.accessSync(path);
|
||||||
|
} catch {
|
||||||
|
// do nothing
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function main({ n, type }) {
|
function main({ n, type }) {
|
||||||
let path;
|
let path;
|
||||||
|
|
||||||
@ -29,14 +39,10 @@ function main({ n, type }) {
|
|||||||
default:
|
default:
|
||||||
new Error('Invalid type');
|
new Error('Invalid type');
|
||||||
}
|
}
|
||||||
|
// warmup
|
||||||
|
runBench(n, path);
|
||||||
|
|
||||||
bench.start();
|
bench.start();
|
||||||
for (let i = 0; i < n; i++) {
|
runBench(n, path);
|
||||||
try {
|
|
||||||
fs.accessSync(path);
|
|
||||||
} catch {
|
|
||||||
// do nothing
|
|
||||||
}
|
|
||||||
}
|
|
||||||
bench.end(n);
|
bench.end(n);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user