mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00
benchmark: add more options to cp-sync
PR-URL: https://github.com/nodejs/node/pull/58278 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
This commit is contained in:
parent
cd68e35704
commit
60273710ef
1 changed files with 38 additions and 5 deletions
|
@ -4,20 +4,53 @@ 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],
|
||||
dereference: ['true', 'false'],
|
||||
force: ['true', 'false'],
|
||||
});
|
||||
|
||||
function main({ n }) {
|
||||
function prepareTestDirectory() {
|
||||
const testDir = tmpdir.resolve(`test-cp-${process.pid}`);
|
||||
fs.mkdirSync(testDir, { recursive: true });
|
||||
|
||||
fs.writeFileSync(path.join(testDir, 'source.txt'), 'test content');
|
||||
|
||||
fs.symlinkSync(
|
||||
path.join(testDir, 'source.txt'),
|
||||
path.join(testDir, 'link.txt'),
|
||||
);
|
||||
|
||||
return testDir;
|
||||
}
|
||||
|
||||
function main({ n, dereference, force }) {
|
||||
tmpdir.refresh();
|
||||
const options = { recursive: true };
|
||||
const src = path.join(__dirname, '../../test/fixtures/copy');
|
||||
|
||||
const src = prepareTestDirectory();
|
||||
const dest = tmpdir.resolve(`${process.pid}/subdir/cp-bench-${process.pid}`);
|
||||
|
||||
const options = {
|
||||
recursive: true,
|
||||
dereference: dereference === 'true',
|
||||
force: force === 'true',
|
||||
};
|
||||
|
||||
if (options.force) {
|
||||
fs.cpSync(src, dest, { recursive: true });
|
||||
}
|
||||
|
||||
bench.start();
|
||||
for (let i = 0; i < n; i++) {
|
||||
fs.cpSync(src, dest, options);
|
||||
if (options.force) {
|
||||
fs.cpSync(src, dest, options);
|
||||
} else {
|
||||
const uniqueDest = tmpdir.resolve(
|
||||
`${process.pid}/subdir/cp-bench-${process.pid}-${i}`,
|
||||
);
|
||||
fs.cpSync(src, uniqueDest, options);
|
||||
}
|
||||
}
|
||||
bench.end(n);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue