Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: add access async version to bench #54747

Merged
merged 2 commits into from
Sep 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
Loading