2016-05-14 15:24:34 -07:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common.js');
|
2017-06-04 14:25:44 -04:00
|
|
|
const { exec, execSync } = require('child_process');
|
|
|
|
const isWindows = process.platform === 'win32';
|
2016-05-31 18:25:15 +02:00
|
|
|
|
2017-09-13 22:48:53 -03:00
|
|
|
const messagesLength = [64, 256, 1024, 4096];
|
2017-06-04 14:25:44 -04:00
|
|
|
// Windows does not support command lines longer than 8191 characters
|
|
|
|
if (!isWindows) messagesLength.push(32768);
|
|
|
|
|
|
|
|
const bench = common.createBenchmark(childProcessExecStdout, {
|
2016-05-31 18:25:15 +02:00
|
|
|
len: messagesLength,
|
2023-01-29 20:13:35 +02:00
|
|
|
dur: [5],
|
2016-05-14 15:24:34 -07:00
|
|
|
});
|
|
|
|
|
2017-12-30 04:00:22 +01:00
|
|
|
function childProcessExecStdout({ dur, len }) {
|
2016-05-14 15:24:34 -07:00
|
|
|
bench.start();
|
|
|
|
|
2017-12-30 04:00:22 +01:00
|
|
|
const maxDuration = dur * 1000;
|
2017-06-04 14:25:44 -04:00
|
|
|
const cmd = `yes "${'.'.repeat(len)}"`;
|
|
|
|
const child = exec(cmd, { 'stdio': ['ignore', 'pipe', 'ignore'] });
|
2016-05-14 15:24:34 -07:00
|
|
|
|
2019-12-20 17:01:49 +01:00
|
|
|
let bytes = 0;
|
2017-06-04 14:25:44 -04:00
|
|
|
child.stdout.on('data', (msg) => {
|
2016-05-14 15:24:34 -07:00
|
|
|
bytes += msg.length;
|
|
|
|
});
|
|
|
|
|
2017-06-04 14:25:44 -04:00
|
|
|
setTimeout(() => {
|
2016-05-14 15:24:34 -07:00
|
|
|
bench.end(bytes);
|
2017-06-04 14:25:44 -04:00
|
|
|
if (isWindows) {
|
|
|
|
// Sometimes there's a yes.exe process left hanging around on Windows.
|
|
|
|
try {
|
|
|
|
execSync(`taskkill /f /t /pid ${child.pid}`);
|
2018-11-04 12:38:54 -05:00
|
|
|
} catch {
|
2018-12-03 17:15:45 +01:00
|
|
|
// This is a best effort kill. stderr is piped to parent for tracing.
|
2017-06-04 14:25:44 -04:00
|
|
|
}
|
2017-04-25 13:48:50 -07:00
|
|
|
} else {
|
|
|
|
child.kill();
|
|
|
|
}
|
2017-06-04 14:25:44 -04:00
|
|
|
}, maxDuration);
|
2016-05-14 15:24:34 -07:00
|
|
|
}
|