summaryrefslogtreecommitdiff
path: root/benchmark/http
diff options
context:
space:
mode:
authorRuben Bridgewater <ruben@bridgewater.de>2017-12-30 03:57:46 +0100
committerRuben Bridgewater <ruben@bridgewater.de>2018-01-23 01:29:28 +0100
commita52878c23911df269cd86dbca35d1d75a6468efe (patch)
tree2cf815e89c0d694cc876089b522005aeaa8616e7 /benchmark/http
parentfd45187d345c8c11533da52b0c8c8b658dd40d80 (diff)
downloadandroid-node-v8-a52878c23911df269cd86dbca35d1d75a6468efe.tar.gz
android-node-v8-a52878c23911df269cd86dbca35d1d75a6468efe.tar.bz2
android-node-v8-a52878c23911df269cd86dbca35d1d75a6468efe.zip
benchmark: (http) use destructuring
PR-URL: https://github.com/nodejs/node/pull/18250 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'benchmark/http')
-rw-r--r--benchmark/http/_chunky_http_client.js6
-rw-r--r--benchmark/http/bench-parser.js4
-rw-r--r--benchmark/http/check_invalid_header_char.js5
-rw-r--r--benchmark/http/check_is_http_token.js5
-rw-r--r--benchmark/http/chunked.js8
-rw-r--r--benchmark/http/client-request-body.js9
-rw-r--r--benchmark/http/cluster.js6
-rw-r--r--benchmark/http/create-clientrequest.js5
-rw-r--r--benchmark/http/end-vs-write-end.js11
-rw-r--r--benchmark/http/simple.js7
10 files changed, 24 insertions, 42 deletions
diff --git a/benchmark/http/_chunky_http_client.js b/benchmark/http/_chunky_http_client.js
index ee1f4f8caa..a90535e489 100644
--- a/benchmark/http/_chunky_http_client.js
+++ b/benchmark/http/_chunky_http_client.js
@@ -11,9 +11,7 @@ const bench = common.createBenchmark(main, {
});
-function main(conf) {
- const len = +conf.len;
- const num = +conf.n;
+function main({ len, n }) {
var todo = [];
const headers = [];
// Chose 7 because 9 showed "Connection error" / "Connection closed"
@@ -78,7 +76,7 @@ function main(conf) {
size = (size * mult + add) % mod;
if (did) {
count += 1;
- if (count === num) {
+ if (count === n) {
bench.end(count);
process.exit(0);
} else {
diff --git a/benchmark/http/bench-parser.js b/benchmark/http/bench-parser.js
index 1bc661e728..4c691d7134 100644
--- a/benchmark/http/bench-parser.js
+++ b/benchmark/http/bench-parser.js
@@ -15,9 +15,7 @@ const bench = common.createBenchmark(main, {
});
-function main(conf) {
- const len = conf.len >>> 0;
- const n = conf.n >>> 0;
+function main({ len, n }) {
var header = `GET /hello HTTP/1.1${CRLF}Content-Type: text/plain${CRLF}`;
for (var i = 0; i < len; i++) {
diff --git a/benchmark/http/check_invalid_header_char.js b/benchmark/http/check_invalid_header_char.js
index d71bc6fc60..b9933d690e 100644
--- a/benchmark/http/check_invalid_header_char.js
+++ b/benchmark/http/check_invalid_header_char.js
@@ -30,10 +30,7 @@ const bench = common.createBenchmark(main, {
n: [1e6],
});
-function main(conf) {
- const n = +conf.n;
- const key = conf.key;
-
+function main({ n, key }) {
bench.start();
for (var i = 0; i < n; i++) {
_checkInvalidHeaderChar(key);
diff --git a/benchmark/http/check_is_http_token.js b/benchmark/http/check_is_http_token.js
index 92df3445b4..c16993819b 100644
--- a/benchmark/http/check_is_http_token.js
+++ b/benchmark/http/check_is_http_token.js
@@ -40,10 +40,7 @@ const bench = common.createBenchmark(main, {
n: [1e6],
});
-function main(conf) {
- const n = +conf.n;
- const key = conf.key;
-
+function main({ n, key }) {
bench.start();
for (var i = 0; i < n; i++) {
_checkIsHttpToken(key);
diff --git a/benchmark/http/chunked.js b/benchmark/http/chunked.js
index 1056f456ef..5615395ee0 100644
--- a/benchmark/http/chunked.js
+++ b/benchmark/http/chunked.js
@@ -16,9 +16,9 @@ const bench = common.createBenchmark(main, {
c: [100]
});
-function main(conf) {
+function main({ len, n, c }) {
const http = require('http');
- const chunk = Buffer.alloc(conf.len, '8');
+ const chunk = Buffer.alloc(len, '8');
const server = http.createServer(function(req, res) {
function send(left) {
@@ -28,12 +28,12 @@ function main(conf) {
send(left - 1);
}, 0);
}
- send(conf.n);
+ send(n);
});
server.listen(common.PORT, function() {
bench.http({
- connections: conf.c
+ connections: c
}, function() {
server.close();
});
diff --git a/benchmark/http/client-request-body.js b/benchmark/http/client-request-body.js
index a6849580cf..49bb9130ae 100644
--- a/benchmark/http/client-request-body.js
+++ b/benchmark/http/client-request-body.js
@@ -11,13 +11,10 @@ const bench = common.createBenchmark(main, {
method: ['write', 'end']
});
-function main(conf) {
- const dur = +conf.dur;
- const len = +conf.len;
-
+function main({ dur, len, type, method }) {
var encoding;
var chunk;
- switch (conf.type) {
+ switch (type) {
case 'buf':
chunk = Buffer.alloc(len, 'x');
break;
@@ -55,7 +52,7 @@ function main(conf) {
pummel(); // Line up next request.
res.resume();
});
- if (conf.method === 'write') {
+ if (method === 'write') {
req.write(chunk, encoding);
req.end();
} else {
diff --git a/benchmark/http/cluster.js b/benchmark/http/cluster.js
index 352b1d2645..56393fa1ab 100644
--- a/benchmark/http/cluster.js
+++ b/benchmark/http/cluster.js
@@ -15,7 +15,7 @@ if (cluster.isMaster) {
require('../fixtures/simple-http-server.js').listen(port);
}
-function main(conf) {
+function main({ type, len, c }) {
process.env.PORT = PORT;
var workers = 0;
const w1 = cluster.fork();
@@ -27,11 +27,11 @@ function main(conf) {
return;
setTimeout(function() {
- const path = `/${conf.type}/${conf.len}`;
+ const path = `/${type}/${len}`;
bench.http({
path: path,
- connections: conf.c
+ connections: c
}, function() {
w1.destroy();
w2.destroy();
diff --git a/benchmark/http/create-clientrequest.js b/benchmark/http/create-clientrequest.js
index d19a6fb434..97316a7e80 100644
--- a/benchmark/http/create-clientrequest.js
+++ b/benchmark/http/create-clientrequest.js
@@ -8,10 +8,7 @@ const bench = common.createBenchmark(main, {
n: [1e6]
});
-function main(conf) {
- const len = +conf.len;
- const n = +conf.n;
-
+function main({ len, n }) {
const path = '/'.repeat(len);
const opts = { path: path, createConnection: function() {} };
diff --git a/benchmark/http/end-vs-write-end.js b/benchmark/http/end-vs-write-end.js
index b7db1eaa78..f839e5c3cd 100644
--- a/benchmark/http/end-vs-write-end.js
+++ b/benchmark/http/end-vs-write-end.js
@@ -17,11 +17,10 @@ const bench = common.createBenchmark(main, {
method: ['write', 'end']
});
-function main(conf) {
+function main({ len, type, method, c }) {
const http = require('http');
var chunk;
- const len = conf.len;
- switch (conf.type) {
+ switch (type) {
case 'buf':
chunk = Buffer.alloc(len, 'x');
break;
@@ -42,15 +41,15 @@ function main(conf) {
res.end(chunk);
}
- const method = conf.method === 'write' ? write : end;
+ const fn = method === 'write' ? write : end;
const server = http.createServer(function(req, res) {
- method(res);
+ fn(res);
});
server.listen(common.PORT, function() {
bench.http({
- connections: conf.c
+ connections: c
}, function() {
server.close();
});
diff --git a/benchmark/http/simple.js b/benchmark/http/simple.js
index 544aad4968..d5351815fc 100644
--- a/benchmark/http/simple.js
+++ b/benchmark/http/simple.js
@@ -12,17 +12,16 @@ const bench = common.createBenchmark(main, {
res: ['normal', 'setHeader', 'setHeaderWH']
});
-function main(conf) {
+function main({ type, len, chunks, c, chunkedEnc, res }) {
process.env.PORT = PORT;
var server = require('../fixtures/simple-http-server.js')
.listen(PORT)
.on('listening', function() {
- const path =
- `/${conf.type}/${conf.len}/${conf.chunks}/${conf.res}/${conf.chunkedEnc}`;
+ const path = `/${type}/${len}/${chunks}/${res}/${chunkedEnc}`;
bench.http({
path: path,
- connections: conf.c
+ connections: c
}, function() {
server.close();
});