-
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
mkdirSync
- Loading branch information
1 parent
dc1c50b
commit 92b3a70
Showing
4 changed files
with
60 additions
and
18 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,44 @@ | ||
'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); | ||
} |
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