Skip to content

Commit 4173aea

Browse files
committed
benchmark: add fs.copyFile(p, dst, constants.COPYFILE_FICLONE_FORCE)
Refs: nodejs/performance#110 Signed-off-by: Juan José Arboleda <soyjuanarbol@gmail.com>
1 parent 6825d88 commit 4173aea

1 file changed

Lines changed: 40 additions & 0 deletions

File tree

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
'use strict';
2+
3+
const common = require('../common');
4+
const { copyFile } = require('fs/promises');
5+
const { constants } = require('fs');
6+
const tmpdir = require('../../test/common/tmpdir');
7+
tmpdir.refresh();
8+
9+
const bench = common.createBenchmark(main, {
10+
type: ['invalid', 'valid'],
11+
method: ['ficlone', 'ficlone_force'],
12+
n: [1e4],
13+
});
14+
15+
async function main({ n, type }) {
16+
tmpdir.refresh();
17+
const dest = tmpdir.resolve(`copy-file-bench-${process.pid}`);
18+
let path;
19+
20+
switch (type) {
21+
case 'invalid':
22+
path = tmpdir.resolve(`.existing-file-${process.pid}`);
23+
break;
24+
case 'valid':
25+
path = __filename;
26+
break;
27+
default:
28+
throw new Error('Invalid type');
29+
}
30+
31+
bench.start();
32+
for (let i = 0; i < n; i++) {
33+
try {
34+
await copyFile(path, dest, constants.COPYFILE_FICLONE_FORCE);
35+
} catch {
36+
// do nothing
37+
}
38+
}
39+
bench.end(n);
40+
}

0 commit comments

Comments
 (0)