File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -5,15 +5,48 @@ const Readable = require('stream').Readable;
55
66const bench = common . createBenchmark ( main , {
77 n : [ 1e7 ] ,
8+ type : [ 'array' , 'sync-generator' , 'async-generator' ] ,
89} ) ;
910
10- async function main ( { n } ) {
11- const arr = [ ] ;
12- for ( let i = 0 ; i < n ; i ++ ) {
13- arr . push ( `${ i } ` ) ;
11+ async function main ( { n, type } ) {
12+ let fromArg ;
13+
14+ switch ( type ) {
15+ case 'array' : {
16+ fromArg = [ ] ;
17+ for ( let i = 0 ; i < n ; i ++ ) {
18+ fromArg . push ( `${ i } ` ) ;
19+ }
20+
21+ break ;
22+ }
23+
24+ case 'sync-generator' : {
25+ fromArg = ( function * ( ) {
26+ for ( let i = 0 ; i < n ; i ++ ) {
27+ yield `${ i } ` ;
28+ }
29+ } ) ( ) ;
30+
31+ break ;
32+ }
33+
34+ case 'async-generator' : {
35+ fromArg = ( async function * ( ) {
36+ for ( let i = 0 ; i < n ; i ++ ) {
37+ yield `${ i } ` ;
38+ }
39+ } ) ( ) ;
40+
41+ break ;
42+ }
43+
44+ default : {
45+ throw new Error ( `Unknown type: ${ type } ` ) ;
46+ }
1447 }
1548
16- const s = new Readable . from ( arr ) ;
49+ const s = new Readable . from ( fromArg ) ;
1750
1851 bench . start ( ) ;
1952 s . on ( 'data' , ( data ) => {
You can’t perform that action at this time.
0 commit comments