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

Function main

benchmark/dgram/single-buffer.js:18–53  ·  view source on GitHub ↗
({ dur, len, n, type })

Source from the content-addressed store, hash-verified

16});
17
18function main({ dur, len, n, type }) {
19 const chunk = Buffer.allocUnsafe(len);
20 let sent = 0;
21 let received = 0;
22 const socket = dgram.createSocket('udp4');
23
24 function onsend() {
25 if (sent++ % n === 0) {
26 // The setImmediate() is necessary to have event loop progress on OSes
27 // that only perform synchronous I/O on nonblocking UDP sockets.
28 setImmediate(() => {
29 for (let i = 0; i < n; i++) {
30 socket.send(chunk, PORT, '127.0.0.1', onsend);
31 }
32 });
33 }
34 }
35
36 socket.on('listening', () => {
37 bench.start();
38 onsend();
39
40 setTimeout(() => {
41 const bytes = (type === 'send' ? sent : received) * chunk.length;
42 const gbits = (bytes * 8) / (1024 * 1024 * 1024);
43 bench.end(gbits);
44 process.exit(0);
45 }, dur * 1000);
46 });
47
48 socket.on('message', () => {
49 received++;
50 });
51
52 socket.bind(PORT);
53}

Callers

nothing calls this directly

Calls 8

createSocketMethod · 0.80
onsendFunction · 0.70
setTimeoutFunction · 0.50
onMethod · 0.45
startMethod · 0.45
endMethod · 0.45
exitMethod · 0.45
bindMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…