-
Notifications
You must be signed in to change notification settings - Fork 29.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: improve error performance for
rmdirSync
PR-URL: #49846 Refs: nodejs/performance#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>
- Loading branch information
1 parent
0c85ceb
commit f94a24c
Showing
4 changed files
with
50 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters