-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
Expand file tree
/
Copy pathbench-cpSync.js
More file actions
56 lines (45 loc) · 1.28 KB
/
bench-cpSync.js
File metadata and controls
56 lines (45 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
'use strict';
const common = require('../common');
const fs = require('fs');
const path = require('path');
const tmpdir = require('../../test/common/tmpdir');
const bench = common.createBenchmark(main, {
n: [1, 100, 10_000],
dereference: ['true', 'false'],
force: ['true', 'false'],
});
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 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++) {
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);
}