MCPcopy Index your code
hub / github.com/nodejs/node / main

Function main

benchmark/child_process/child-process-ipc-roundtrip.js:16–46  ·  view source on GitHub ↗
({ dur, len, serialization })

Source from the content-addressed store, hash-verified

14 const { spawn } = require('child_process');
15
16 function main({ dur, len, serialization }) {
17 const msg = { payload: '.'.repeat(len) };
18 const options = {
19 stdio: ['ignore', 'ignore', 'ignore', 'ipc'],
20 serialization,
21 };
22 const child = spawn(process.argv[0],
23 [process.argv[1], 'child'], options);
24
25 let messages = 0;
26 let finished = false;
27
28 child.on('message', () => {
29 messages++;
30 // Keep one round-trip in flight per completed one so both the serialize
31 // (write) and deserialize (read) paths stay saturated on both ends.
32 if (!finished)
33 child.send(msg);
34 });
35
36 bench.start();
37 // Prime a window of in-flight messages so the IPC channel never drains.
38 for (let i = 0; i < 256; i++)
39 child.send(msg);
40
41 setTimeout(() => {
42 finished = true;
43 bench.end(messages);
44 child.kill();
45 }, dur * 1000);
46 }
47}

Callers

nothing calls this directly

Calls 7

killMethod · 0.80
sendMethod · 0.65
spawnFunction · 0.50
setTimeoutFunction · 0.50
onMethod · 0.45
startMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…