-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Read up to 32 directory entries in one batch when `dir.readSync()` or `dir.read()` are called. This increases performance significantly, although it introduces quite a bit of edge case complexity. confidence improvement accuracy (*) (**) (***) fs/bench-opendir.js mode='async' dir='lib' n=100 *** 155.93 % ±30.05% ±40.34% ±53.21% fs/bench-opendir.js mode='async' dir='test/parallel' n=100 *** 479.65 % ±56.81% ±76.47% ±101.32% fs/bench-opendir.js mode='sync' dir='lib' n=100 10.38 % ±14.39% ±19.16% ±24.96% fs/bench-opendir.js mode='sync' dir='test/parallel' n=100 *** 63.13 % ±12.84% ±17.18% ±22.58% PR-URL: #29893 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: David Carlier <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Jeremiah Senkpiel <[email protected]>
- Loading branch information
Showing
5 changed files
with
143 additions
and
45 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,51 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [100], | ||
dir: [ 'lib', 'test/parallel'], | ||
mode: [ 'async', 'sync', 'callback' ] | ||
}); | ||
|
||
async function main({ n, dir, mode }) { | ||
const fullPath = path.resolve(__dirname, '../../', dir); | ||
|
||
bench.start(); | ||
|
||
let counter = 0; | ||
for (let i = 0; i < n; i++) { | ||
if (mode === 'async') { | ||
// eslint-disable-next-line no-unused-vars | ||
for await (const entry of await fs.promises.opendir(fullPath)) | ||
counter++; | ||
} else if (mode === 'callback') { | ||
const dir = await fs.promises.opendir(fullPath); | ||
await new Promise((resolve, reject) => { | ||
function read() { | ||
dir.read((err, entry) => { | ||
if (err) { | ||
reject(err); | ||
} else if (entry === null) { | ||
resolve(dir.close()); | ||
} else { | ||
counter++; | ||
read(); | ||
} | ||
}); | ||
} | ||
|
||
read(); | ||
}); | ||
} else { | ||
const dir = fs.opendirSync(fullPath); | ||
while (dir.readSync() !== null) | ||
counter++; | ||
dir.closeSync(); | ||
} | ||
} | ||
|
||
bench.end(counter); | ||
} |
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
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