-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: simpler and faster Readable async iterator
Reimplement as an async generator instead of a custom iterator class. Backport-PR-URL: #34887 PR-URL: #34035 Refs: #34680 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
- Loading branch information
1 parent
ffae5f3
commit 4bb4007
Showing
7 changed files
with
121 additions
and
269 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,38 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const Readable = require('stream').Readable; | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1e5], | ||
sync: ['yes', 'no'], | ||
}); | ||
|
||
async function main({ n, sync }) { | ||
sync = sync === 'yes'; | ||
|
||
const s = new Readable({ | ||
objectMode: true, | ||
read() { | ||
if (sync) { | ||
this.push(1); | ||
} else { | ||
process.nextTick(() => { | ||
this.push(1); | ||
}); | ||
} | ||
} | ||
}); | ||
|
||
bench.start(); | ||
|
||
let x = 0; | ||
for await (const chunk of s) { | ||
x += chunk; | ||
if (x > n) { | ||
break; | ||
} | ||
} | ||
|
||
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
This file was deleted.
Oops, something went wrong.
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
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
Oops, something went wrong.