-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fs: refactoring declaratively with
Array.fromAsync
Refs: #51912 PR-URL: #54644 Reviewed-By: Daeyeon Jeong <[email protected]>
- Loading branch information
Showing
3 changed files
with
40 additions
and
4 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,37 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const assert = require('node:assert'); | ||
|
||
const benchmarkDirectory = path.resolve(__dirname, '..', '..'); | ||
|
||
const configs = { | ||
n: [1e3], | ||
dir: ['lib'], | ||
pattern: ['**/*', '*.js', '**/**.js'], | ||
mode: ['async', 'sync'], | ||
recursive: ['true', 'false'], | ||
}; | ||
|
||
const bench = common.createBenchmark(main, configs); | ||
|
||
async function main(config) { | ||
const fullPath = path.resolve(benchmarkDirectory, config.dir); | ||
const { pattern, recursive, mode } = config; | ||
|
||
let noDead; | ||
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 }); | ||
} | ||
} | ||
|
||
bench.end(config.n); | ||
assert.ok(noDead); | ||
} |
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