mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
f11b2061ea
PR-URL: https://github.com/nodejs/node/pull/49846 Refs: https://github.com/nodejs/performance/issues/106 Reviewed-By: Yagiz Nizipli <yagiz.nizipli@sentry.io> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
43 lines
918 B
JavaScript
43 lines
918 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: [1e4],
|
|
});
|
|
|
|
function main({ n, type }) {
|
|
switch (type) {
|
|
case 'existing': {
|
|
for (let i = 0; i < n; i++) {
|
|
fs.mkdirSync(tmpdir.resolve(`rmdirsync-bench-dir-${i}`));
|
|
}
|
|
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
fs.rmdirSync(tmpdir.resolve(`rmdirsync-bench-dir-${i}`));
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
}
|
|
case 'non-existing': {
|
|
bench.start();
|
|
for (let i = 0; i < n; i++) {
|
|
try {
|
|
fs.rmdirSync(tmpdir.resolve(`.non-existent-folder-${i}`));
|
|
} catch {
|
|
// do nothing
|
|
}
|
|
}
|
|
bench.end(n);
|
|
break;
|
|
}
|
|
default:
|
|
new Error('Invalid type');
|
|
}
|
|
}
|