11'use strict' ;
22const common = require ( '../common.js' ) ;
3+
4+ // This benchmark uses `yes` to a create noisy child_processes with varying
5+ // output message lengths, and tries to read 8GB of output
6+
37const os = require ( 'os' ) ;
8+ const child_process = require ( 'child_process' ) ;
49
510var messagesLength = [ 64 , 256 , 1024 , 4096 ] ;
611// Windows does not support that long arguments
@@ -12,7 +17,6 @@ const bench = common.createBenchmark(main, {
1217 dur : [ 5 ]
1318} ) ;
1419
15- const spawn = require ( 'child_process' ) . spawn ;
1620function main ( conf ) {
1721 bench . start ( ) ;
1822
@@ -21,15 +25,20 @@ function main(conf) {
2125
2226 const msg = `"${ '.' . repeat ( len ) } "` ;
2327 const options = { 'stdio' : [ 'ignore' , 'pipe' , 'ignore' ] } ;
24- const child = spawn ( 'yes' , [ msg ] , options ) ;
28+ const child = child_process . spawn ( 'yes' , [ msg ] , options ) ;
2529
2630 var bytes = 0 ;
2731 child . stdout . on ( 'data' , function ( msg ) {
2832 bytes += msg . length ;
2933 } ) ;
3034
3135 setTimeout ( function ( ) {
32- child . kill ( ) ;
36+ if ( process . platform === 'win32' ) {
37+ // Sometimes there's a yes.exe process left hanging around on Windows...
38+ child_process . execSync ( `taskkill /f /t /pid ${ child . pid } ` ) ;
39+ } else {
40+ child . kill ( ) ;
41+ }
3342 const gbits = ( bytes * 8 ) / ( 1024 * 1024 * 1024 ) ;
3443 bench . end ( gbits ) ;
3544 } , dur * 1000 ) ;
0 commit comments