0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-24 03:07:54 +01:00
nodejs/benchmark/fs/bench-rmdirSync.js
CanadaHonk f11b2061ea
fs: improve error performance for rmdirSync
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>
2023-11-26 19:23:41 +00:00

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');
}
}