Skip to content

Commit

Permalink
benchmark: add access async version to bench
Browse files Browse the repository at this point in the history
PR-URL: #54747
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Rich Trott <[email protected]>
  • Loading branch information
RafaelGSS authored and targos committed Oct 2, 2024
1 parent b877972 commit 2393f21
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions benchmark/fs/bench-accessSync.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ fs.writeFileSync(tmpfile, 'this-is-for-a-benchmark', 'utf8');

const bench = common.createBenchmark(main, {
type: ['existing', 'non-existing', 'non-flat-existing'],
method: ['access', 'accessSync'],
n: [1e5],
});

Expand All @@ -23,7 +24,17 @@ function runBench(n, path) {
}
}

function main({ n, type }) {
function runAsyncBench(n, path) {
(function r(cntr, path) {
if (cntr-- <= 0)
return bench.end(n);
fs.access(path, () => {
r(cntr, path);
});
})(n, path);
}

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

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

bench.start();
runBench(n, path);
bench.end(n);
if (method === 'access') {
// Warmup the filesystem - it doesn't need to use the async method
runBench(n, path);

bench.start();
runAsyncBench(n, path);
} else {
// warmup
runBench(n, path);

bench.start();
runBench(n, path);
bench.end(n);
}
}

0 comments on commit 2393f21

Please sign in to comment.