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

Function main

benchmark/dgram/send-types.js:14–52  ·  view source on GitHub ↗
({ type, chunks, len, n })

Source from the content-addressed store, hash-verified

12});
13
14function main({ type, chunks, len, n }) {
15 const socket = dgram.createSocket('udp4');
16
17 let testData;
18 switch (type) {
19 case 'string':
20 testData = Array(chunks).fill('a'.repeat(len));
21 break;
22 case 'buffer':
23 testData = Array(chunks).fill(Buffer.alloc(len, 'a'));
24 break;
25 case 'mixed':
26 testData = [];
27 for (let i = 0; i < chunks; i++) {
28 if (i % 2 === 0) {
29 testData.push(Buffer.alloc(len, 'a'));
30 } else {
31 testData.push('a'.repeat(len));
32 }
33 }
34 break;
35 case 'typedarray':
36 testData = Array(chunks).fill(new Uint8Array(len).fill(97));
37 break;
38 }
39
40 bench.start();
41
42 for (let i = 0; i < n; i++) {
43 socket.send(testData, 12345, 'localhost', (err) => {
44 if (err && err.code !== 'ENOTCONN' && err.code !== 'ECONNREFUSED') {
45 throw err;
46 }
47 });
48 }
49
50 bench.end(n);
51 socket.close();
52}

Callers

nothing calls this directly

Calls 9

ArrayFunction · 0.85
createSocketMethod · 0.80
fillMethod · 0.80
allocMethod · 0.80
sendMethod · 0.65
closeMethod · 0.65
pushMethod · 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…