From 895fcb05462268a56ac1e51ce00dc2ecbbbfd438 Mon Sep 17 00:00:00 2001 From: Yagiz Nizipli Date: Thu, 27 Jun 2024 17:13:21 -0400 Subject: [PATCH] benchmark: add cpSync benchmark MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit PR-URL: https://github.com/nodejs/node/pull/53612 Reviewed-By: Chemi Atlow Reviewed-By: LiviaMedeiros Reviewed-By: Vinícius Lourenço Claro Cardoso Reviewed-By: Benjamin Gruenbaum --- benchmark/fs/bench-cpSync.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 benchmark/fs/bench-cpSync.js diff --git a/benchmark/fs/bench-cpSync.js b/benchmark/fs/bench-cpSync.js new file mode 100644 index 00000000000000..f3ad9c26b35c0f --- /dev/null +++ b/benchmark/fs/bench-cpSync.js @@ -0,0 +1,23 @@ +'use strict'; + +const common = require('../common'); +const fs = require('fs'); +const path = require('path'); +const tmpdir = require('../../test/common/tmpdir'); +tmpdir.refresh(); + +const bench = common.createBenchmark(main, { + n: [1, 100, 10_000], +}); + +function main({ n }) { + tmpdir.refresh(); + const options = { force: true, recursive: true }; + const src = path.join(__dirname, '../../test/fixtures/copy'); + const dest = tmpdir.resolve(`${process.pid}/subdir/cp-bench-${process.pid}`); + bench.start(); + for (let i = 0; i < n; i++) { + fs.cpSync(src, dest, options); + } + bench.end(n); +}