mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
6bc7fa7906
PR-URL: https://github.com/nodejs/node/pull/49859 Refs: https://github.com/nodejs/performance/issues/106 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
42 lines
942 B
JavaScript
42 lines
942 B
JavaScript
'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');
|
|
}
|
|
}
|