1'use strict'; 2if (process.argv[2] === 'child') { 3 const len = +process.argv[3]; 4 const msg = '.'.repeat(len); 5 const send = () => { 6 while (process.send(msg)); 7 // Wait: backlog of unsent messages exceeds threshold 8 setImmediate(send); 9 }; 10 send(); 11} else { 12 const common = require('../common.js'); 13 const bench = common.createBenchmark(main, { 14 len: [ 15 64, 256, 1024, 4096, 16384, 65536, 16 65536 << 4, 65536 << 6 - 1, 17 ], 18 dur: [5] 19 }); 20 const spawn = require('child_process').spawn; 21 22 function main({ dur, len }) { 23 bench.start(); 24 25 const options = { 'stdio': ['ignore', 1, 2, 'ipc'] }; 26 const child = spawn(process.argv[0], 27 [process.argv[1], 'child', len], options); 28 29 let bytes = 0; 30 child.on('message', (msg) => { bytes += msg.length; }); 31 32 setTimeout(() => { 33 child.kill(); 34 bench.end(bytes); 35 }, dur * 1000); 36 } 37} 38