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

Function main

benchmark/http/bench-parser-fragmented.js:13–67  ·  view source on GitHub ↗
({ len, frags, n })

Source from the content-addressed store, hash-verified

11});
12
13function main({ len, frags, n }) {
14 const { HTTPParser } = common.binding('http_parser');
15 const REQUEST = HTTPParser.REQUEST;
16 const kOnHeaders = HTTPParser.kOnHeaders | 0;
17 const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0;
18 const kOnBody = HTTPParser.kOnBody | 0;
19 const kOnMessageComplete = HTTPParser.kOnMessageComplete | 0;
20
21 function processHeaderFragmented(fragments, n) {
22 const parser = newParser(REQUEST);
23
24 bench.start();
25 for (let i = 0; i < n; i++) {
26 // Send header in fragments
27 for (const frag of fragments) {
28 parser.execute(frag, 0, frag.length);
29 }
30 parser.initialize(REQUEST, {});
31 }
32 bench.end(n);
33 }
34
35 function newParser(type) {
36 const parser = new HTTPParser();
37 parser.initialize(type, {});
38
39 parser.headers = [];
40
41 parser[kOnHeaders] = function() { };
42 parser[kOnHeadersComplete] = function() { };
43 parser[kOnBody] = function() { };
44 parser[kOnMessageComplete] = function() { };
45
46 return parser;
47 }
48
49 // Build the header
50 let header = `GET /hello HTTP/1.1\r\nContent-Type: text/plain\r\n`;
51
52 for (let i = 0; i < len; i++) {
53 header += `X-Filler${i}: ${Math.random().toString(36).substring(2)}\r\n`;
54 }
55 header += '\r\n';
56
57 // Split header into fragments
58 const headerBuf = Buffer.from(header);
59 const fragSize = Math.ceil(headerBuf.length / frags);
60 const fragments = [];
61
62 for (let i = 0; i < headerBuf.length; i += fragSize) {
63 fragments.push(headerBuf.slice(i, Math.min(i + fragSize, headerBuf.length)));
64 }
65
66 processHeaderFragmented(fragments, n);
67}

Callers

nothing calls this directly

Calls 7

processHeaderFragmentedFunction · 0.85
randomMethod · 0.80
sliceMethod · 0.65
toStringMethod · 0.45
fromMethod · 0.45
pushMethod · 0.45
minMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…