summaryrefslogtreecommitdiff
path: root/deps/node/benchmark/child_process
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2019-04-03 15:43:32 +0200
committerFlorian Dold <florian.dold@gmail.com>2019-04-03 15:45:57 +0200
commit71e285b94c7edaa43aa8115965cf5a36b8e0f80a (patch)
tree7d4aa9d0d5aff686b106cd5da72ba77960c4af43 /deps/node/benchmark/child_process
parent7dadf9356b4f3f4137ce982ea5bb960283116e9a (diff)
downloadakono-71e285b94c7edaa43aa8115965cf5a36b8e0f80a.tar.gz
akono-71e285b94c7edaa43aa8115965cf5a36b8e0f80a.tar.bz2
akono-71e285b94c7edaa43aa8115965cf5a36b8e0f80a.zip
Node.js v11.13.0
Diffstat (limited to 'deps/node/benchmark/child_process')
-rw-r--r--deps/node/benchmark/child_process/child-process-exec-stdout.js40
-rw-r--r--deps/node/benchmark/child_process/child-process-params.js142
-rw-r--r--deps/node/benchmark/child_process/child-process-read-ipc.js37
-rw-r--r--deps/node/benchmark/child_process/child-process-read.js42
-rw-r--r--deps/node/benchmark/child_process/spawn-echo.js24
5 files changed, 285 insertions, 0 deletions
diff --git a/deps/node/benchmark/child_process/child-process-exec-stdout.js b/deps/node/benchmark/child_process/child-process-exec-stdout.js
new file mode 100644
index 00000000..a1dc4aa0
--- /dev/null
+++ b/deps/node/benchmark/child_process/child-process-exec-stdout.js
@@ -0,0 +1,40 @@
+'use strict';
+const common = require('../common.js');
+const { exec, execSync } = require('child_process');
+const isWindows = process.platform === 'win32';
+
+const messagesLength = [64, 256, 1024, 4096];
+// Windows does not support command lines longer than 8191 characters
+if (!isWindows) messagesLength.push(32768);
+
+const bench = common.createBenchmark(childProcessExecStdout, {
+ len: messagesLength,
+ dur: [5]
+});
+
+function childProcessExecStdout({ dur, len }) {
+ bench.start();
+
+ const maxDuration = dur * 1000;
+ const cmd = `yes "${'.'.repeat(len)}"`;
+ const child = exec(cmd, { 'stdio': ['ignore', 'pipe', 'ignore'] });
+
+ var bytes = 0;
+ child.stdout.on('data', (msg) => {
+ bytes += msg.length;
+ });
+
+ setTimeout(() => {
+ bench.end(bytes);
+ 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.
+ }
+ } else {
+ child.kill();
+ }
+ }, maxDuration);
+}
diff --git a/deps/node/benchmark/child_process/child-process-params.js b/deps/node/benchmark/child_process/child-process-params.js
new file mode 100644
index 00000000..df930395
--- /dev/null
+++ b/deps/node/benchmark/child_process/child-process-params.js
@@ -0,0 +1,142 @@
+'use strict';
+
+const common = require('../common.js');
+const cp = require('child_process');
+
+const command = 'echo';
+const args = ['hello'];
+const options = {};
+const cb = () => {};
+
+const configs = {
+ n: [1e3],
+ methodName: [
+ 'exec', 'execSync',
+ 'execFile', 'execFileSync',
+ 'spawn', 'spawnSync',
+ ],
+ params: [1, 2, 3, 4],
+};
+
+const bench = common.createBenchmark(main, configs);
+
+function main({ n, methodName, params }) {
+ const method = cp[methodName];
+
+ switch (methodName) {
+ case 'exec':
+ switch (params) {
+ case 1:
+ bench.start();
+ for (let i = 0; i < n; i++) method(command).kill();
+ bench.end(n);
+ break;
+ case 2:
+ bench.start();
+ for (let i = 0; i < n; i++) method(command, options).kill();
+ bench.end(n);
+ break;
+ case 3:
+ bench.start();
+ for (let i = 0; i < n; i++) method(command, options, cb).kill();
+ bench.end(n);
+ break;
+ }
+ break;
+ case 'execSync':
+ switch (params) {
+ case 1:
+ bench.start();
+ for (let i = 0; i < n; i++) method(command);
+ bench.end(n);
+ break;
+ case 2:
+ bench.start();
+ for (let i = 0; i < n; i++) method(command, options);
+ bench.end(n);
+ break;
+ }
+ break;
+ case 'execFile':
+ switch (params) {
+ case 1:
+ bench.start();
+ for (let i = 0; i < n; i++) method(command).kill();
+ bench.end(n);
+ break;
+ case 2:
+ bench.start();
+ for (let i = 0; i < n; i++) method(command, args).kill();
+ bench.end(n);
+ break;
+ case 3:
+ bench.start();
+ for (let i = 0; i < n; i++) method(command, args, options).kill();
+ bench.end(n);
+ break;
+ case 4:
+ bench.start();
+ for (let i = 0; i < n; i++) method(command, args, options, cb).kill();
+ bench.end(n);
+ break;
+ }
+ break;
+ case 'execFileSync':
+ switch (params) {
+ case 1:
+ bench.start();
+ for (let i = 0; i < n; i++) method(command);
+ bench.end(n);
+ break;
+ case 2:
+ bench.start();
+ for (let i = 0; i < n; i++) method(command, args);
+ bench.end(n);
+ break;
+ case 3:
+ bench.start();
+ for (let i = 0; i < n; i++) method(command, args, options);
+ bench.end(n);
+ break;
+ }
+ break;
+ case 'spawn':
+ switch (params) {
+ case 1:
+ bench.start();
+ for (let i = 0; i < n; i++) method(command).kill();
+ bench.end(n);
+ break;
+ case 2:
+ bench.start();
+ for (let i = 0; i < n; i++) method(command, args).kill();
+ bench.end(n);
+ break;
+ case 3:
+ bench.start();
+ for (let i = 0; i < n; i++) method(command, args, options).kill();
+ bench.end(n);
+ break;
+ }
+ break;
+ case 'spawnSync':
+ switch (params) {
+ case 1:
+ bench.start();
+ for (let i = 0; i < n; i++) method(command);
+ bench.end(n);
+ break;
+ case 2:
+ bench.start();
+ for (let i = 0; i < n; i++) method(command, args);
+ bench.end(n);
+ break;
+ case 3:
+ bench.start();
+ for (let i = 0; i < n; i++) method(command, args, options);
+ bench.end(n);
+ break;
+ }
+ break;
+ }
+}
diff --git a/deps/node/benchmark/child_process/child-process-read-ipc.js b/deps/node/benchmark/child_process/child-process-read-ipc.js
new file mode 100644
index 00000000..a9e9cdf7
--- /dev/null
+++ b/deps/node/benchmark/child_process/child-process-read-ipc.js
@@ -0,0 +1,37 @@
+'use strict';
+if (process.argv[2] === 'child') {
+ const len = +process.argv[3];
+ const msg = '.'.repeat(len);
+ const send = () => {
+ while (process.send(msg));
+ // Wait: backlog of unsent messages exceeds threshold
+ setImmediate(send);
+ };
+ send();
+} else {
+ const common = require('../common.js');
+ const bench = common.createBenchmark(main, {
+ len: [
+ 64, 256, 1024, 4096, 16384, 65536,
+ 65536 << 4, 65536 << 8,
+ ],
+ dur: [5]
+ });
+ const spawn = require('child_process').spawn;
+
+ function main({ dur, len }) {
+ bench.start();
+
+ const options = { 'stdio': ['ignore', 1, 2, 'ipc'] };
+ const child = spawn(process.argv[0],
+ [process.argv[1], 'child', len], options);
+
+ var bytes = 0;
+ child.on('message', (msg) => { bytes += msg.length; });
+
+ setTimeout(() => {
+ child.kill();
+ bench.end(bytes);
+ }, dur * 1000);
+ }
+}
diff --git a/deps/node/benchmark/child_process/child-process-read.js b/deps/node/benchmark/child_process/child-process-read.js
new file mode 100644
index 00000000..3c014411
--- /dev/null
+++ b/deps/node/benchmark/child_process/child-process-read.js
@@ -0,0 +1,42 @@
+'use strict';
+const common = require('../common.js');
+
+// This benchmark uses `yes` to a create noisy child_processes with varying
+// output message lengths, and tries to read 8GB of output
+
+const os = require('os');
+const child_process = require('child_process');
+
+const messagesLength = [64, 256, 1024, 4096];
+// Windows does not support that long arguments
+if (os.platform() !== 'win32')
+ messagesLength.push(32768);
+
+const bench = common.createBenchmark(main, {
+ len: messagesLength,
+ dur: [5]
+});
+
+function main({ dur, len }) {
+ bench.start();
+
+ const msg = `"${'.'.repeat(len)}"`;
+ const options = { 'stdio': ['ignore', 'pipe', 'ignore'] };
+ const child = child_process.spawn('yes', [msg], options);
+
+ var bytes = 0;
+ child.stdout.on('data', (msg) => {
+ bytes += msg.length;
+ });
+
+ setTimeout(() => {
+ if (process.platform === 'win32') {
+ // Sometimes there's a yes.exe process left hanging around on Windows...
+ child_process.execSync(`taskkill /f /t /pid ${child.pid}`);
+ } else {
+ child.kill();
+ }
+ const gbits = (bytes * 8) / (1024 * 1024 * 1024);
+ bench.end(gbits);
+ }, dur * 1000);
+}
diff --git a/deps/node/benchmark/child_process/spawn-echo.js b/deps/node/benchmark/child_process/spawn-echo.js
new file mode 100644
index 00000000..8f5c80cd
--- /dev/null
+++ b/deps/node/benchmark/child_process/spawn-echo.js
@@ -0,0 +1,24 @@
+'use strict';
+const common = require('../common.js');
+const bench = common.createBenchmark(main, {
+ n: [1000]
+});
+
+const spawn = require('child_process').spawn;
+function main({ n }) {
+ bench.start();
+ go(n, n);
+}
+
+function go(n, left) {
+ if (--left === 0)
+ return bench.end(n);
+
+ const child = spawn('echo', ['hello']);
+ child.on('exit', (code) => {
+ if (code)
+ process.exit(code);
+ else
+ go(n, left);
+ });
+}