11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciif (process.argv[2] === 'child') { 31cb0ef41Sopenharmony_ci const len = +process.argv[3]; 41cb0ef41Sopenharmony_ci const msg = '.'.repeat(len); 51cb0ef41Sopenharmony_ci const send = () => { 61cb0ef41Sopenharmony_ci while (process.send(msg)); 71cb0ef41Sopenharmony_ci // Wait: backlog of unsent messages exceeds threshold 81cb0ef41Sopenharmony_ci setImmediate(send); 91cb0ef41Sopenharmony_ci }; 101cb0ef41Sopenharmony_ci send(); 111cb0ef41Sopenharmony_ci} else { 121cb0ef41Sopenharmony_ci const common = require('../common.js'); 131cb0ef41Sopenharmony_ci const bench = common.createBenchmark(main, { 141cb0ef41Sopenharmony_ci len: [ 151cb0ef41Sopenharmony_ci 64, 256, 1024, 4096, 16384, 65536, 161cb0ef41Sopenharmony_ci 65536 << 4, 65536 << 6 - 1, 171cb0ef41Sopenharmony_ci ], 181cb0ef41Sopenharmony_ci dur: [5], 191cb0ef41Sopenharmony_ci }); 201cb0ef41Sopenharmony_ci const spawn = require('child_process').spawn; 211cb0ef41Sopenharmony_ci 221cb0ef41Sopenharmony_ci function main({ dur, len }) { 231cb0ef41Sopenharmony_ci bench.start(); 241cb0ef41Sopenharmony_ci 251cb0ef41Sopenharmony_ci const options = { 'stdio': ['ignore', 1, 2, 'ipc'] }; 261cb0ef41Sopenharmony_ci const child = spawn(process.argv[0], 271cb0ef41Sopenharmony_ci [process.argv[1], 'child', len], options); 281cb0ef41Sopenharmony_ci 291cb0ef41Sopenharmony_ci let bytes = 0; 301cb0ef41Sopenharmony_ci child.on('message', (msg) => { bytes += msg.length; }); 311cb0ef41Sopenharmony_ci 321cb0ef41Sopenharmony_ci setTimeout(() => { 331cb0ef41Sopenharmony_ci child.kill(); 341cb0ef41Sopenharmony_ci bench.end(bytes); 351cb0ef41Sopenharmony_ci }, dur * 1000); 361cb0ef41Sopenharmony_ci } 371cb0ef41Sopenharmony_ci} 38