0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 13:09:21 +01:00

benchmark: add stream.compose benchmark

PR-URL: https://github.com/nodejs/node/pull/54308
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
jakecastelli 2024-08-12 22:10:04 +09:30 committed by GitHub
parent 9a4eb210ae
commit 87ee722873
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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);
}