-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
fs.mkdtempSync
- Loading branch information
Showing
4 changed files
with
96 additions
and
17 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,38 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const fs = require('fs'); | ||
const tmpdir = require('../../test/common/tmpdir'); | ||
tmpdir.refresh(); | ||
|
||
const nonexistentDir = tmpdir.resolve('non-existent', 'foo', 'bar'); | ||
const bench = common.createBenchmark(main, { | ||
type: ['valid', 'invalid'], | ||
n: [1e3], | ||
}); | ||
|
||
function main({ n, type }) { | ||
let prefix; | ||
|
||
switch (type) { | ||
case 'valid': | ||
prefix = `${Date.now()}`; | ||
break; | ||
case 'invalid': | ||
prefix = nonexistentDir; | ||
break; | ||
default: | ||
new Error('Invalid type'); | ||
} | ||
|
||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
try { | ||
const folderPath = fs.mkdtempSync(prefix, { encoding: 'utf8' }); | ||
fs.rmdirSync(folderPath); | ||
} 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