Skip to content

benchmark: add stream.compose benchmark #54308

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions benchmark/streams/compose.js
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);
}
Loading