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

Function main

benchmark/dgram/array-vs-concat.js:19–67  ·  view source on GitHub ↗
({ dur, len, n, type, chunks })

Source from the content-addressed store, hash-verified

17});
18
19function main({ dur, len, n, type, chunks }) {
20 const chunk = [];
21 for (let i = 0; i < chunks; i++) {
22 chunk.push(Buffer.allocUnsafe(Math.round(len / chunks)));
23 }
24
25 // Server
26 let sent = 0;
27 const socket = dgram.createSocket('udp4');
28 const onsend = type === 'concat' ? onsendConcat : onsendMulti;
29
30 function onsendConcat() {
31 if (sent++ % n === 0) {
32 // The setImmediate() is necessary to have event loop progress on OSes
33 // that only perform synchronous I/O on nonblocking UDP sockets.
34 setImmediate(() => {
35 for (let i = 0; i < n; i++) {
36 socket.send(Buffer.concat(chunk), PORT, '127.0.0.1', onsend);
37 }
38 });
39 }
40 }
41
42 function onsendMulti() {
43 if (sent++ % n === 0) {
44 // The setImmediate() is necessary to have event loop progress on OSes
45 // that only perform synchronous I/O on nonblocking UDP sockets.
46 setImmediate(() => {
47 for (let i = 0; i < n; i++) {
48 socket.send(chunk, PORT, '127.0.0.1', onsend);
49 }
50 });
51 }
52 }
53
54 socket.on('listening', () => {
55 bench.start();
56 onsend();
57
58 setTimeout(() => {
59 const bytes = sent * len;
60 const gbits = (bytes * 8) / (1024 * 1024 * 1024);
61 bench.end(gbits);
62 process.exit(0);
63 }, dur * 1000);
64 });
65
66 socket.bind(PORT);
67}

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected