File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+
3+ const common = require ( '../common' ) ;
4+ const { Readable, Writable, Duplex, finished } = require ( 'stream' ) ;
5+
6+ const bench = common . createBenchmark ( main , {
7+ n : [ 1e5 ] ,
8+ streamType : [ 'readable' , 'writable' , 'duplex' ] ,
9+ } ) ;
10+
11+ function main ( { n, streamType } ) {
12+ bench . start ( ) ;
13+
14+ for ( let i = 0 ; i < n ; i ++ ) {
15+ let stream ;
16+
17+ switch ( streamType ) {
18+ case 'readable' :
19+ stream = new Readable ( { read ( ) { this . push ( null ) ; } } ) ;
20+ break ;
21+ case 'writable' :
22+ stream = new Writable ( { write ( chunk , enc , cb ) { cb ( ) ; } } ) ;
23+ stream . end ( ) ;
24+ break ;
25+ case 'duplex' :
26+ stream = new Duplex ( {
27+ read ( ) { this . push ( null ) ; } ,
28+ write ( chunk , enc , cb ) { cb ( ) ; } ,
29+ } ) ;
30+ stream . end ( ) ;
31+ break ;
32+ }
33+
34+ finished ( stream , ( ) => { } ) ;
35+ }
36+
37+ bench . end ( n ) ;
38+ }
You can’t perform that action at this time.
0 commit comments