-
-
Notifications
You must be signed in to change notification settings - Fork 35.5k
fs: refactoring declaratively with the Array.fromAsync function #54644
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
07d075a
e2d8a69
dde434c
f4025e5
1a9ae15
db16e20
43ef1e4
cb2591a
1ff400e
c976446
7dbb93f
defe492
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
PR: #54644 (comment)
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | ||||||||
| 'use strict'; | ||||||||
|
|
||||||||
| const common = require('../common'); | ||||||||
| const fs = require('fs'); | ||||||||
| const path = require('path'); | ||||||||
|
|
||||||||
| const benchmarkDirectory = path.resolve(__dirname, '..', '..'); | ||||||||
|
|
||||||||
| const configs = { | ||||||||
| n: [1, 10, 100], | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO 100 is way to low. |
||||||||
| dir: ['lib', 'test/parallel', 'benchmark'], | ||||||||
| pattern: ['**/*', '*.js', '**/**.js'], | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: There seem to be too many cases. Suggest reducing a few options if possible. Please consider if it's possible to obtain sufficient results with fewer iterations and cases.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you so much for the review! I thought about it this way: dir: ['lib'],
pattern: ['**/*', '*.js', '**/**.js'],
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I think the configs would be enough.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you! There were definitely a variety of cases..! I fixed from defe492! |
||||||||
| mode: ['async', 'sync'], | ||||||||
|
aduh95 marked this conversation as resolved.
|
||||||||
| recursive: ['true', 'false'] | ||||||||
| }; | ||||||||
|
|
||||||||
| const bench = common.createBenchmark(main, configs); | ||||||||
|
|
||||||||
| async function main(conf) { | ||||||||
| const fullPath = path.resolve(benchmarkDirectory, conf.dir); | ||||||||
| const globPattern = conf.pattern; | ||||||||
| const recursive = conf.recursive === 'true'; | ||||||||
|
|
||||||||
| bench.start(); | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
|
|
||||||||
| let counter = 0; | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
No need to count the output |
||||||||
| for (let i = 0; i < conf.n; i++) { | ||||||||
| if (conf.mode === 'async') { | ||||||||
| const matches = await new Promise((resolve, reject) => { | ||||||||
| fs.glob(globPattern, { cwd: fullPath, recursive }, (err, files) => { | ||||||||
| if (err) reject(err); | ||||||||
| else resolve(files); | ||||||||
| }); | ||||||||
| }); | ||||||||
| counter += matches.length; | ||||||||
| } else if (conf.mode === 'sync') { | ||||||||
| const matches = fs.globSync(globPattern, { cwd: fullPath, recursive }); | ||||||||
| counter += matches.length; | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| bench.end(counter); | ||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
| } | ||||||||
Uh oh!
There was an error while loading. Please reload this page.