-
-
Notifications
You must be signed in to change notification settings - Fork 34.8k
benchmark: add callback-based fs.glob to glob benchmark
#58417
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
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,7 @@ const configs = { | |
| n: [1e3], | ||
| dir: ['lib'], | ||
| pattern: ['**/*', '*.js', '**/**.js'], | ||
| mode: ['async', 'sync'], | ||
| mode: ['sync', 'promise', 'callback'], | ||
| recursive: ['true', 'false'], | ||
| }; | ||
|
|
||
|
|
@@ -25,10 +25,26 @@ async function main(config) { | |
| bench.start(); | ||
|
|
||
| for (let i = 0; i < config.n; i++) { | ||
| if (mode === 'async') { | ||
| noDead = await fs.promises.glob(pattern, { cwd: fullPath, recursive }); | ||
| } else { | ||
| noDead = fs.globSync(pattern, { cwd: fullPath, recursive }); | ||
| switch (mode) { | ||
| case 'sync': | ||
| noDead = fs.globSync(pattern, { cwd: fullPath, recursive }); | ||
| break; | ||
| case 'promise': | ||
| noDead = await fs.promises.glob(pattern, { cwd: fullPath, recursive }); | ||
| break; | ||
| case 'callback': | ||
| noDead = await new Promise((resolve, reject) => { | ||
| fs.glob(pattern, { cwd: fullPath, recursive }, (err, matches) => { | ||
| if (err) { | ||
| reject(err); | ||
| } else { | ||
| resolve(matches); | ||
| } | ||
| }); | ||
|
||
| }); | ||
|
||
| break; | ||
| default: | ||
| throw new Error(`Unknown mode: ${mode}`); | ||
| } | ||
| } | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should build the options object outside the loop
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, implemented in 531d6be