Skip to content
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);
}
}