Skip to content

Commit

Permalink
benchmark: add stream.compose benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
jakecastelli committed Aug 10, 2024
1 parent 90d91ab commit 1e0c034
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions benchmark/streams/compose.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
'use strict';
const common = require('../common.js');

const {
Readable,
PassThrough,
Writable,
compose,
} = require('stream');

const bench = common.createBenchmark(main, {
n: [1e3],
});

function main({ n }) {
bench.start();
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() });

const composed = compose(readable, ...passThroughs, writable);
composed.end();
}
bench.end(n);
}

0 comments on commit 1e0c034

Please sign in to comment.