Skip to content

Commit 2393f21

Browse files
RafaelGSStargos
authored andcommitted
benchmark: add access async version to bench
PR-URL: #54747 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Rich Trott <[email protected]>
1 parent b877972 commit 2393f21

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

benchmark/fs/bench-accessSync.js

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ fs.writeFileSync(tmpfile, 'this-is-for-a-benchmark', 'utf8');
1010

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

@@ -23,7 +24,17 @@ function runBench(n, path) {
2324
}
2425
}
2526

26-
function main({ n, type }) {
27+
function runAsyncBench(n, path) {
28+
(function r(cntr, path) {
29+
if (cntr-- <= 0)
30+
return bench.end(n);
31+
fs.access(path, () => {
32+
r(cntr, path);
33+
});
34+
})(n, path);
35+
}
36+
37+
function main({ n, type, method }) {
2738
let path;
2839

2940
switch (type) {
@@ -39,10 +50,19 @@ function main({ n, type }) {
3950
default:
4051
new Error('Invalid type');
4152
}
42-
// warmup
43-
runBench(n, path);
4453

45-
bench.start();
46-
runBench(n, path);
47-
bench.end(n);
54+
if (method === 'access') {
55+
// Warmup the filesystem - it doesn't need to use the async method
56+
runBench(n, path);
57+
58+
bench.start();
59+
runAsyncBench(n, path);
60+
} else {
61+
// warmup
62+
runBench(n, path);
63+
64+
bench.start();
65+
runBench(n, path);
66+
bench.end(n);
67+
}
4868
}

0 commit comments

Comments
 (0)