1
1
'use strict' ;
2
2
const 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
+
3
7
const os = require ( 'os' ) ;
8
+ const child_process = require ( 'child_process' ) ;
4
9
5
10
var messagesLength = [ 64 , 256 , 1024 , 4096 ] ;
6
11
// Windows does not support that long arguments
@@ -12,7 +17,6 @@ const bench = common.createBenchmark(main, {
12
17
dur : [ 5 ]
13
18
} ) ;
14
19
15
- const spawn = require ( 'child_process' ) . spawn ;
16
20
function main ( conf ) {
17
21
bench . start ( ) ;
18
22
@@ -21,15 +25,20 @@ function main(conf) {
21
25
22
26
const msg = `"${ '.' . repeat ( len ) } "` ;
23
27
const options = { 'stdio' : [ 'ignore' , 'pipe' , 'ignore' ] } ;
24
- const child = spawn ( 'yes' , [ msg ] , options ) ;
28
+ const child = child_process . spawn ( 'yes' , [ msg ] , options ) ;
25
29
26
30
var bytes = 0 ;
27
31
child . stdout . on ( 'data' , function ( msg ) {
28
32
bytes += msg . length ;
29
33
} ) ;
30
34
31
35
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
+ }
33
42
const gbits = ( bytes * 8 ) / ( 1024 * 1024 * 1024 ) ;
34
43
bench . end ( gbits ) ;
35
44
} , dur * 1000 ) ;
0 commit comments