benchmark: cleanup child_process IPC benchmark

Squashed from:
- child_process: fix IPC bench to obey send() ret val
- child_process: fix IPC benchmark message has two more bytes
- child_process: use setImmediate for IPC bench

PR-URL: https://github.com/nodejs/node/pull/10557
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
pull/10407/head
Yuya Tanaka 2017-01-01 00:09:59 +09:00 committed by Anna Henningsen
parent 338d09d25b
commit 1216a34590
No known key found for this signature in database
GPG Key ID: D8B9F5AEAE84E4CF
1 changed files with 13 additions and 8 deletions

View File

@ -1,14 +1,20 @@
'use strict'; 'use strict';
if (process.argv[2] === 'child') { if (process.argv[2] === 'child') {
const len = +process.argv[3]; const len = +process.argv[3];
const msg = `"${'.'.repeat(len)}"`; const msg = '.'.repeat(len);
while (true) { const send = () => {
process.send(msg); while (process.send(msg));
} // Wait: backlog of unsent messages exceeds threshold
setImmediate(send);
};
send();
} else { } else {
const common = require('../common.js'); const common = require('../common.js');
const bench = common.createBenchmark(main, { const bench = common.createBenchmark(main, {
len: [64, 256, 1024, 4096, 32768], len: [
64, 256, 1024, 4096, 16384, 65536,
65536 << 4, 65536 << 8
],
dur: [5] dur: [5]
}); });
const spawn = require('child_process').spawn; const spawn = require('child_process').spawn;
@ -18,7 +24,7 @@ if (process.argv[2] === 'child') {
const dur = +conf.dur; const dur = +conf.dur;
const len = +conf.len; const len = +conf.len;
const options = { 'stdio': ['ignore', 'ignore', 'ignore', 'ipc'] }; const options = { 'stdio': ['ignore', 1, 2, 'ipc'] };
const child = spawn(process.argv[0], const child = spawn(process.argv[0],
[process.argv[1], 'child', len], options); [process.argv[1], 'child', len], options);
@ -29,8 +35,7 @@ if (process.argv[2] === 'child') {
setTimeout(function() { setTimeout(function() {
child.kill(); child.kill();
const gbits = (bytes * 8) / (1024 * 1024 * 1024); bench.end(bytes);
bench.end(gbits);
}, dur * 1000); }, dur * 1000);
} }
} }