-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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 of
linkSync
PR-URL: #49962 Refs: nodejs/performance#106 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Stephen Belanger <[email protected]> Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
- Loading branch information
Showing
4 changed files
with
60 additions
and
13 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,50 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const fs = require('fs'); | ||
const assert = require('assert'); | ||
const tmpdir = require('../../test/common/tmpdir'); | ||
|
||
tmpdir.refresh(); | ||
const tmpfile = tmpdir.resolve(`.bench-file-data-${Date.now()}`); | ||
fs.writeFileSync(tmpfile, 'bench-file', 'utf-8'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
type: ['valid', 'invalid'], | ||
n: [1e3], | ||
}); | ||
|
||
function main({ n, type }) { | ||
switch (type) { | ||
case 'valid': { | ||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
fs.linkSync(tmpfile, tmpdir.resolve(`.valid-${i}`), 'file'); | ||
} | ||
bench.end(n); | ||
|
||
break; | ||
} | ||
|
||
case 'invalid': { | ||
let hasError = false; | ||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
try { | ||
fs.linkSync( | ||
tmpdir.resolve(`.non-existing-file-for-linkSync-${i}`), | ||
__filename, | ||
'file', | ||
); | ||
} catch { | ||
hasError = true; | ||
} | ||
} | ||
bench.end(n); | ||
assert(hasError); | ||
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