From 237d7dfbde7db0648b601233d679893263536e9e Mon Sep 17 00:00:00 2001 From: Rafael Gonzaga Date: Thu, 5 Sep 2024 17:56:54 -0300 Subject: [PATCH] benchmark: add access async version to bench PR-URL: https://github.com/nodejs/node/pull/54747 Reviewed-By: Yagiz Nizipli Reviewed-By: Rich Trott --- benchmark/fs/bench-accessSync.js | 32 ++++++++++++++++++++++++++------ 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/benchmark/fs/bench-accessSync.js b/benchmark/fs/bench-accessSync.js index bf0718634b1d01..0be0ca799d3a36 100644 --- a/benchmark/fs/bench-accessSync.js +++ b/benchmark/fs/bench-accessSync.js @@ -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], }); @@ -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) { @@ -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); + } }