forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
http: move process.binding('http_parser') to internalBinding
Refs: nodejs#22160 PR-URL: nodejs#22329 Reviewed-By: Gus Caplan <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Jon Moss <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
- Loading branch information
Showing
14 changed files
with
84 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,54 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const HTTPParser = process.binding('http_parser').HTTPParser; | ||
const REQUEST = HTTPParser.REQUEST; | ||
const kOnHeaders = HTTPParser.kOnHeaders | 0; | ||
const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0; | ||
const kOnBody = HTTPParser.kOnBody | 0; | ||
const kOnMessageComplete = HTTPParser.kOnMessageComplete | 0; | ||
const CRLF = '\r\n'; | ||
|
||
const bench = common.createBenchmark(main, { | ||
len: [4, 8, 16, 32], | ||
n: [1e5], | ||
n: [1e5] | ||
}, { | ||
flags: ['--expose-internals', '--no-warnings'] | ||
}); | ||
|
||
function main({ len, n }) { | ||
var header = `GET /hello HTTP/1.1${CRLF}Content-Type: text/plain${CRLF}`; | ||
|
||
for (var i = 0; i < len; i++) { | ||
header += `X-Filler${i}: ${Math.random().toString(36).substr(2)}${CRLF}`; | ||
const { internalBinding } = require('internal/test/binding'); | ||
const { HTTPParser } = internalBinding('http_parser'); | ||
const REQUEST = HTTPParser.REQUEST; | ||
const kOnHeaders = HTTPParser.kOnHeaders | 0; | ||
const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0; | ||
const kOnBody = HTTPParser.kOnBody | 0; | ||
const kOnMessageComplete = HTTPParser.kOnMessageComplete | 0; | ||
const CRLF = '\r\n'; | ||
|
||
function processHeader(header, n) { | ||
const parser = newParser(REQUEST); | ||
|
||
bench.start(); | ||
for (var i = 0; i < n; i++) { | ||
parser.execute(header, 0, header.length); | ||
parser.reinitialize(REQUEST); | ||
} | ||
bench.end(n); | ||
} | ||
header += CRLF; | ||
|
||
processHeader(Buffer.from(header), n); | ||
} | ||
function newParser(type) { | ||
const parser = new HTTPParser(type); | ||
|
||
function processHeader(header, n) { | ||
const parser = newParser(REQUEST); | ||
parser.headers = []; | ||
|
||
bench.start(); | ||
for (var i = 0; i < n; i++) { | ||
parser.execute(header, 0, header.length); | ||
parser.reinitialize(REQUEST); | ||
} | ||
bench.end(n); | ||
} | ||
parser[kOnHeaders] = function() { }; | ||
parser[kOnHeadersComplete] = function() { }; | ||
parser[kOnBody] = function() { }; | ||
parser[kOnMessageComplete] = function() { }; | ||
|
||
function newParser(type) { | ||
const parser = new HTTPParser(type); | ||
return parser; | ||
} | ||
|
||
parser.headers = []; | ||
let header = `GET /hello HTTP/1.1${CRLF}Content-Type: text/plain${CRLF}`; | ||
|
||
parser[kOnHeaders] = function() { }; | ||
parser[kOnHeadersComplete] = function() { }; | ||
parser[kOnBody] = function() { }; | ||
parser[kOnMessageComplete] = function() { }; | ||
for (var i = 0; i < len; i++) { | ||
header += `X-Filler${i}: ${Math.random().toString(36).substr(2)}${CRLF}`; | ||
} | ||
header += CRLF; | ||
|
||
return parser; | ||
processHeader(Buffer.from(header), n); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters