-
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: use pushValueToArray for readdir(Sync)
Improve performance by pushing directory entries to returned array in batches of 8 using pushValueToArray() in JS. Add benchmarks to demonstrate this improvement. PR-URL: #3780 Reviewed-By: Fedor Indutny <fedor@indutny.com>
- Loading branch information
1 parent
b8366e7
commit e742422
Showing
3 changed files
with
72 additions
and
6 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,22 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const fs = require('fs'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1e4], | ||
}); | ||
|
||
|
||
function main(conf) { | ||
const n = conf.n >>> 0; | ||
|
||
bench.start(); | ||
(function r(cntr) { | ||
if (--cntr <= 0) | ||
return bench.end(n); | ||
fs.readdir(__dirname + '/../../lib/', function() { | ||
r(cntr); | ||
}); | ||
}(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const fs = require('fs'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1e4], | ||
}); | ||
|
||
|
||
function main(conf) { | ||
const n = conf.n >>> 0; | ||
|
||
bench.start(); | ||
for (var i = 0; i < n; i++) { | ||
fs.readdirSync(__dirname + '/../../lib/'); | ||
} | ||
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