From 23269717bbf1427a683d04ec13a4120ceecd1e09 Mon Sep 17 00:00:00 2001 From: Rafael Gonzaga Date: Sat, 14 Oct 2023 16:51:30 -0300 Subject: [PATCH] benchmark: add warmup to accessSync bench PR-URL: https://github.com/nodejs/node/pull/50073 Reviewed-By: Yagiz Nizipli --- benchmark/fs/bench-accessSync.js | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/benchmark/fs/bench-accessSync.js b/benchmark/fs/bench-accessSync.js index a80504620580ce..bf0718634b1d01 100644 --- a/benchmark/fs/bench-accessSync.js +++ b/benchmark/fs/bench-accessSync.js @@ -13,6 +13,16 @@ const bench = common.createBenchmark(main, { n: [1e5], }); +function runBench(n, path) { + for (let i = 0; i < n; i++) { + try { + fs.accessSync(path); + } catch { + // do nothing + } + } +} + function main({ n, type }) { let path; @@ -29,14 +39,10 @@ function main({ n, type }) { default: new Error('Invalid type'); } + // warmup + runBench(n, path); bench.start(); - for (let i = 0; i < n; i++) { - try { - fs.accessSync(path); - } catch { - // do nothing - } - } + runBench(n, path); bench.end(n); }