2016-05-15 00:24:34 +02:00
|
|
|
'use strict';
|
|
|
|
const common = require('../common.js');
|
2017-06-04 20:25:44 +02:00
|
|
|
const { exec, execSync } = require('child_process');
|
|
|
|
const isWindows = process.platform === 'win32';
|
2016-05-31 18:25:15 +02:00
|
|
|
|
2017-09-14 03:48:53 +02:00
|
|
|
const messagesLength = [64, 256, 1024, 4096];
|
2017-06-04 20:25:44 +02: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,
|
2016-05-15 00:24:34 +02:00
|
|
|
dur: [5]
|
|
|
|
});
|
|
|
|
|
2017-06-04 20:25:44 +02:00
|
|
|
function childProcessExecStdout(conf) {
|
2016-05-15 00:24:34 +02:00
|
|
|
bench.start();
|
|
|
|
|
2017-06-04 20:25:44 +02:00
|
|
|
const maxDuration = conf.dur * 1000;
|
2016-05-15 00:24:34 +02:00
|
|
|
const len = +conf.len;
|
|
|
|
|
2017-06-04 20:25:44 +02:00
|
|
|
const cmd = `yes "${'.'.repeat(len)}"`;
|
|
|
|
const child = exec(cmd, { 'stdio': ['ignore', 'pipe', 'ignore'] });
|
2016-05-15 00:24:34 +02:00
|
|
|
|
|
|
|
var bytes = 0;
|
2017-06-04 20:25:44 +02:00
|
|
|
child.stdout.on('data', (msg) => {
|
2016-05-15 00:24:34 +02:00
|
|
|
bytes += msg.length;
|
|
|
|
});
|
|
|
|
|
2017-06-04 20:25:44 +02:00
|
|
|
setTimeout(() => {
|
2016-05-15 00:24:34 +02:00
|
|
|
bench.end(bytes);
|
2017-06-04 20:25:44 +02:00
|
|
|
if (isWindows) {
|
|
|
|
// Sometimes there's a yes.exe process left hanging around on Windows.
|
|
|
|
try {
|
|
|
|
execSync(`taskkill /f /t /pid ${child.pid}`);
|
|
|
|
} catch (_) {
|
|
|
|
// this is a best effort kill. stderr is piped to parent for tracing.
|
|
|
|
}
|
2017-04-25 22:48:50 +02:00
|
|
|
} else {
|
|
|
|
child.kill();
|
|
|
|
}
|
2017-06-04 20:25:44 +02:00
|
|
|
}, maxDuration);
|
2016-05-15 00:24:34 +02:00
|
|
|
}
|