forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbench-chmodSync.js
More file actions
41 lines (37 loc) · 942 Bytes
/
bench-chmodSync.js
File metadata and controls
41 lines (37 loc) · 942 Bytes
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
'use strict';
const common = require('../common');
const fs = require('fs');
const tmpdir = require('../../test/common/tmpdir');
tmpdir.refresh();
const bench = common.createBenchmark(main, {
type: ['existing', 'non-existing'],
n: [1e3],
});
function main({ n, type }) {
switch (type) {
case 'existing': {
for (let i = 0; i < n; i++) {
fs.writeFileSync(tmpdir.resolve(`chmodsync-bench-file-${i}`), 'bench');
}
bench.start();
for (let i = 0; i < n; i++) {
fs.chmodSync(tmpdir.resolve(`chmodsync-bench-file-${i}`), 0o666);
}
bench.end(n);
break;
}
case 'non-existing':
bench.start();
for (let i = 0; i < n; i++) {
try {
fs.chmodSync(tmpdir.resolve(`chmod-non-existing-file-${i}`), 0o666);
} catch {
// do nothing
}
}
bench.end(n);
break;
default:
new Error('Invalid type');
}
}