MCPcopy Create free account
hub / github.com/nodejs/node / main

Function main

benchmark/net/net-c2s-cork.js:17–63  ·  view source on GitHub ↗
({ dur, len, type })

Source from the content-addressed store, hash-verified

15let encoding;
16
17function main({ dur, len, type }) {
18 switch (type) {
19 case 'buf':
20 chunk = Buffer.alloc(len, 'x');
21 break;
22 case 'utf':
23 encoding = 'utf8';
24 chunk = 'ü'.repeat(len / 2);
25 break;
26 case 'asc':
27 encoding = 'ascii';
28 chunk = 'x'.repeat(len);
29 break;
30 default:
31 throw new Error(`invalid type: ${type}`);
32 }
33
34 const writer = new Writer();
35
36 // The actual benchmark.
37 const server = net.createServer((socket) => {
38 socket.pipe(writer);
39 });
40
41 server.listen(PORT, () => {
42 const socket = net.connect(PORT);
43 socket.on('connect', () => {
44 bench.start();
45
46 socket.on('drain', send);
47 send();
48
49 setTimeout(() => {
50 const bytes = writer.received;
51 const gbits = (bytes * 8) / (1024 * 1024 * 1024);
52 bench.end(gbits);
53 process.exit(0);
54 }, dur * 1000);
55
56 function send() {
57 socket.cork();
58 while (socket.write(chunk, encoding));
59 socket.uncork();
60 }
61 });
62 });
63}
64
65function Writer() {
66 this.received = 0;

Callers

nothing calls this directly

Calls 9

allocMethod · 0.80
listenMethod · 0.80
sendFunction · 0.70
connectMethod · 0.65
setTimeoutFunction · 0.50
onMethod · 0.45
startMethod · 0.45
endMethod · 0.45
exitMethod · 0.45

Tested by

no test coverage detected