Skip to content

Commit 8a89642

Browse files
rluvatonUlisesGascon
authored andcommitted
benchmark: add more cases to Readable.from
PR-URL: #50351 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Vinícius Lourenço Claro Cardoso <[email protected]>
1 parent dbe6c5f commit 8a89642

File tree

1 file changed

+48
-5
lines changed

1 file changed

+48
-5
lines changed

‎benchmark/streams/readable-from.js‎

Lines changed: 48 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,58 @@ const Readable = require('stream').Readable;
55

66
constbench=common.createBenchmark(main,{
77
n: [1e7],
8+
type: ['array','sync-generator-with-sync-values','sync-generator-with-async-values','async-generator'],
89
});
910

10-
asyncfunctionmain({ n }){
11-
constarr=[];
12-
for(leti=0;i<n;i++){
13-
arr.push(`${i}`);
11+
asyncfunctionmain({ n, type }){
12+
letfromArg;
13+
14+
switch(type){
15+
case'array': {
16+
fromArg=[];
17+
for(leti=0;i<n;i++){
18+
fromArg.push(`${i}`);
19+
}
20+
21+
break;
22+
}
23+
24+
case'sync-generator-with-sync-values': {
25+
fromArg=(function*(){
26+
for(leti=0;i<n;i++){
27+
yield`${i}`;
28+
}
29+
})();
30+
31+
break;
32+
}
33+
34+
case'sync-generator-with-async-values': {
35+
fromArg=(function*(){
36+
for(leti=0;i<n;i++){
37+
yieldPromise.resolve(`${i}`);
38+
}
39+
})();
40+
41+
break;
42+
}
43+
44+
case'async-generator': {
45+
fromArg=(asyncfunction*(){
46+
for(leti=0;i<n;i++){
47+
yield`${i}`;
48+
}
49+
})();
50+
51+
break;
52+
}
53+
54+
default: {
55+
thrownewError(`Unknown type: ${type}`);
56+
}
1457
}
1558

16-
consts=newReadable.from(arr);
59+
consts=newReadable.from(fromArg);
1760

1861
bench.start();
1962
s.on('data',(data)=>{

0 commit comments

Comments
(0)