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

Function main

benchmark/net/tcp-raw-c2s.js:20–133  ·  view source on GitHub ↗
({ dur, len, type })

Source from the content-addressed store, hash-verified

18});
19
20function main({ dur, len, type }) {
21 const {
22 TCP,
23 TCPConnectWrap,
24 constants: TCPConstants,
25 } = common.binding('tcp_wrap');
26 const { WriteWrap } = common.binding('stream_wrap');
27 const PORT = common.PORT;
28
29 const serverHandle = new TCP(TCPConstants.SERVER);
30 let err = serverHandle.bind('127.0.0.1', PORT);
31 if (err)
32 fail(err, 'bind');
33
34 err = serverHandle.listen(511);
35 if (err)
36 fail(err, 'listen');
37
38 serverHandle.onconnection = function(err, clientHandle) {
39 if (err)
40 fail(err, 'connect');
41
42 // The meat of the benchmark is right here:
43 bench.start();
44 let bytes = 0;
45
46 setTimeout(() => {
47 // report in Gb/sec
48 bench.end((bytes * 8) / (1024 * 1024 * 1024));
49 process.exit(0);
50 }, dur * 1000);
51
52 clientHandle.onread = function(buffer) {
53 // We're not expecting to ever get an EOF from the client.
54 // Just lots of data forever.
55 if (!buffer)
56 fail('read');
57
58 // Don't slice the buffer. The point of this is to isolate, not
59 // simulate real traffic.
60 bytes += buffer.byteLength;
61 };
62
63 clientHandle.readStart();
64 };
65
66 client(type, len);
67
68 function fail(err, syscall) {
69 throw util._errnoException(err, syscall);
70 }
71
72 function client(type, len) {
73 let chunk;
74 switch (type) {
75 case 'buf':
76 chunk = Buffer.alloc(len, 'x');
77 break;

Callers

nothing calls this directly

Calls 9

listenMethod · 0.80
failFunction · 0.70
clientFunction · 0.70
setTimeoutFunction · 0.50
bindMethod · 0.45
startMethod · 0.45
endMethod · 0.45
exitMethod · 0.45
readStartMethod · 0.45

Tested by

no test coverage detected