1'use strict'; 2const common = require('../common.js'); 3const { exec, execSync } = require('child_process'); 4const isWindows = process.platform === 'win32'; 5 6const messagesLength = [64, 256, 1024, 4096]; 7// Windows does not support command lines longer than 8191 characters 8if (!isWindows) messagesLength.push(32768); 9 10const bench = common.createBenchmark(childProcessExecStdout, { 11 len: messagesLength, 12 dur: [5] 13}); 14 15function 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} 41