-
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.
stream: make Readable.from performance better
PR-URL: #37609 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
- Loading branch information
Showing
2 changed files
with
58 additions
and
19 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,26 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const Readable = require('stream').Readable; | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1e7], | ||
}); | ||
|
||
async function main({ n }) { | ||
const arr = []; | ||
for (let i = 0; i < n; i++) { | ||
arr.push(`${i}`); | ||
} | ||
|
||
const s = new Readable.from(arr); | ||
|
||
bench.start(); | ||
s.on('data', (data) => { | ||
// eslint-disable-next-line no-unused-expressions | ||
data; | ||
}); | ||
s.on('close', () => { | ||
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