mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
c37cf1832c
PR-URL: https://github.com/nodejs/node/pull/49847 Refs: https://github.com/nodejs/performance/issues/106 Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
45 lines
995 B
JavaScript
45 lines
995 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'],
|
|
recursive: ['true', 'false'],
|
|
n: [1e3],
|
|
});
|
|
|
|
function main({ n, type, recursive }) {
|
|
recursive = recursive === 'true';
|
|
let files;
|
|
|
|
switch (type) {
|
|
case 'non-existing':
|
|
files = [];
|
|
|
|
// Populate tmpdir with target dirs
|
|
for (let i = 0; i < n; i++) {
|
|
const path = tmpdir.resolve(recursive ? `rmdirsync-bench-dir-${process.pid}-${i}/a/b/c` : `rmdirsync-bench-dir-${process.pid}-${i}`);
|
|
files.push(path);
|
|
}
|
|
break;
|
|
case 'existing':
|
|
files = new Array(n).fill(__dirname);
|
|
break;
|
|
default:
|
|
new Error('Invalid type');
|
|
}
|
|
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
try {
|
|
fs.mkdirSync(files[i], { recursive });
|
|
} catch {
|
|
// do nothing
|
|
}
|
|
}
|
|
bench.end(n);
|
|
}
|