| 13 | }); |
| 14 | |
| 15 | function childProcessExecStdout({ dur, len }) { |
| 16 | bench.start(); |
| 17 | |
| 18 | const maxDuration = dur * 1000; |
| 19 | const cmd = `yes "${'.'.repeat(len)}"`; |
| 20 | const child = exec(cmd, { 'stdio': ['ignore', 'pipe', 'ignore'] }); |
| 21 | |
| 22 | let bytes = 0; |
| 23 | child.stdout.on('data', (msg) => { |
| 24 | bytes += msg.length; |
| 25 | }); |
| 26 | |
| 27 | setTimeout(() => { |
| 28 | bench.end(bytes); |
| 29 | if (isWindows) { |
| 30 | // Sometimes there's a yes.exe process left hanging around on Windows. |
| 31 | try { |
| 32 | execSync(`taskkill /f /t /pid ${child.pid}`); |
| 33 | } catch { |
| 34 | // This is a best effort kill. stderr is piped to parent for tracing. |
| 35 | } |
| 36 | } else { |
| 37 | child.kill(); |
| 38 | } |
| 39 | }, maxDuration); |
| 40 | } |