2016-05-25 16:33:10 +02:00
|
|
|
'use strict';
|
2016-07-09 02:17:47 +02:00
|
|
|
if (process.argv[2] === 'child') {
|
2016-05-25 16:33:10 +02:00
|
|
|
const len = +process.argv[3];
|
2016-12-31 16:09:59 +01:00
|
|
|
const msg = '.'.repeat(len);
|
|
|
|
const send = () => {
|
|
|
|
while (process.send(msg));
|
|
|
|
// Wait: backlog of unsent messages exceeds threshold
|
|
|
|
setImmediate(send);
|
|
|
|
};
|
|
|
|
send();
|
2016-05-25 16:33:10 +02:00
|
|
|
} else {
|
|
|
|
const common = require('../common.js');
|
|
|
|
const bench = common.createBenchmark(main, {
|
2016-12-31 16:09:59 +01:00
|
|
|
len: [
|
|
|
|
64, 256, 1024, 4096, 16384, 65536,
|
2019-02-05 07:06:08 +01:00
|
|
|
65536 << 4, 65536 << 8,
|
2016-12-31 16:09:59 +01:00
|
|
|
],
|
2016-05-25 16:33:10 +02:00
|
|
|
dur: [5]
|
|
|
|
});
|
|
|
|
const spawn = require('child_process').spawn;
|
|
|
|
|
2017-12-30 04:00:22 +01:00
|
|
|
function main({ dur, len }) {
|
|
|
|
bench.start();
|
2016-05-25 16:33:10 +02:00
|
|
|
|
2016-12-31 16:09:59 +01:00
|
|
|
const options = { 'stdio': ['ignore', 1, 2, 'ipc'] };
|
2016-05-25 16:33:10 +02:00
|
|
|
const child = spawn(process.argv[0],
|
2017-06-24 05:52:07 +02:00
|
|
|
[process.argv[1], 'child', len], options);
|
2016-05-25 16:33:10 +02:00
|
|
|
|
2019-12-20 17:01:49 +01:00
|
|
|
let bytes = 0;
|
2019-02-05 07:06:08 +01:00
|
|
|
child.on('message', (msg) => { bytes += msg.length; });
|
2016-05-25 16:33:10 +02:00
|
|
|
|
2019-02-05 07:06:08 +01:00
|
|
|
setTimeout(() => {
|
2016-05-25 16:33:10 +02:00
|
|
|
child.kill();
|
2016-12-31 16:09:59 +01:00
|
|
|
bench.end(bytes);
|
2016-05-25 16:33:10 +02:00
|
|
|
}, dur * 1000);
|
|
|
|
}
|
|
|
|
}
|