diff options
author | James M Snell <jasnell@gmail.com> | 2018-08-15 03:01:06 +0300 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2018-08-18 23:01:21 +0300 |
commit | 1744205ff565b490f8db72000028b074cce23d5d (patch) | |
tree | 4f1b3fe528d8cd977a501ded10261b87590b7ce8 /benchmark/http/bench-parser.js | |
parent | 4fa5448e5dd8fc06f92f94b170918913aef5bbdb (diff) |
http: move process.binding('http_parser') to internalBinding
Refs: https://github.com/nodejs/node/issues/22160
PR-URL: https://github.com/nodejs/node/pull/22329
Reviewed-By: Gus Caplan <me@gus.host>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Jon Moss <me@jonathanmoss.me>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Diffstat (limited to 'benchmark/http/bench-parser.js')
-rw-r--r-- | benchmark/http/bench-parser.js | 68 |
1 files changed, 36 insertions, 32 deletions
diff --git a/benchmark/http/bench-parser.js b/benchmark/http/bench-parser.js index d629fe67e59..087616f44e7 100644 --- a/benchmark/http/bench-parser.js +++ b/benchmark/http/bench-parser.js @@ -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); } |