Skip to content

Commit 8b71fa7

Browse files
jakecastellitargos
authored andcommitted
benchmark: add stream.compose benchmark
PR-URL: #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>
1 parent c004aba commit 8b71fa7

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

‎benchmark/streams/compose.js‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
'use strict';
2+
constcommon=require('../common.js');
3+
4+
const{
5+
PassThrough,
6+
Readable,
7+
Writable,
8+
compose,
9+
}=require('node:stream');
10+
11+
constbench=common.createBenchmark(main,{
12+
n: [1e3],
13+
});
14+
15+
functionmain({ n }){
16+
constcachedPassThroughs=[];
17+
constcachedReadables=[];
18+
constcachedWritables=[];
19+
20+
for(leti=0;i<n;i++){
21+
constnumberOfPassThroughs=100;
22+
constpassThroughs=[];
23+
24+
for(leti=0;i<numberOfPassThroughs;i++){
25+
passThroughs.push(newPassThrough());
26+
}
27+
28+
constreadable=Readable.from(['hello','world']);
29+
constwritable=newWritable({objectMode: true,write: (chunk,encoding,cb)=>cb()});
30+
31+
cachedPassThroughs.push(passThroughs);
32+
cachedReadables.push(readable);
33+
cachedWritables.push(writable);
34+
}
35+
36+
bench.start();
37+
for(leti=0;i<n;i++){
38+
constcomposed=compose(cachedReadables[i], ...cachedPassThroughs[i],cachedWritables[i]);
39+
composed.end();
40+
}
41+
bench.end(n);
42+
}

0 commit comments

Comments
 (0)