-
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.
benchmark: add stream.compose benchmark
PR-URL: #54308 Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]> Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
1 parent
b236510
commit bfdc96c
Showing
1 changed file
with
42 additions
and
0 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,42 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
|
||
const { | ||
PassThrough, | ||
Readable, | ||
Writable, | ||
compose, | ||
} = require('node:stream'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
n: [1e3], | ||
}); | ||
|
||
function main({ n }) { | ||
const cachedPassThroughs = []; | ||
const cachedReadables = []; | ||
const cachedWritables = []; | ||
|
||
for (let i = 0; i < n; i++) { | ||
const numberOfPassThroughs = 100; | ||
const passThroughs = []; | ||
|
||
for (let i = 0; i < numberOfPassThroughs; i++) { | ||
passThroughs.push(new PassThrough()); | ||
} | ||
|
||
const readable = Readable.from(['hello', 'world']); | ||
const writable = new Writable({ objectMode: true, write: (chunk, encoding, cb) => cb() }); | ||
|
||
cachedPassThroughs.push(passThroughs); | ||
cachedReadables.push(readable); | ||
cachedWritables.push(writable); | ||
} | ||
|
||
bench.start(); | ||
for (let i = 0; i < n; i++) { | ||
const composed = compose(cachedReadables[i], ...cachedPassThroughs[i], cachedWritables[i]); | ||
composed.end(); | ||
} | ||
bench.end(n); | ||
} |