Skip to content

Commit 4e19cbe

Browse files
BridgeARevanlucas
authored andcommitted
benchmark: (http) use destructuring
PR-URL: #18250 Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent e9c426b commit 4e19cbe

10 files changed

+24
-42
lines changed

benchmark/http/_chunky_http_client.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ const bench = common.createBenchmark(main, {
1111
});
1212

1313

14-
function main(conf) {
15-
const len = +conf.len;
16-
const num = +conf.n;
14+
function main({ len, n }) {
1715
var todo = [];
1816
const headers = [];
1917
// Chose 7 because 9 showed "Connection error" / "Connection closed"
@@ -78,7 +76,7 @@ function main(conf) {
7876
size = (size * mult + add) % mod;
7977
if (did) {
8078
count += 1;
81-
if (count === num) {
79+
if (count === n) {
8280
bench.end(count);
8381
process.exit(0);
8482
} else {

benchmark/http/bench-parser.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@ const bench = common.createBenchmark(main, {
1515
});
1616

1717

18-
function main(conf) {
19-
const len = conf.len >>> 0;
20-
const n = conf.n >>> 0;
18+
function main({ len, n }) {
2119
var header = `GET /hello HTTP/1.1${CRLF}Content-Type: text/plain${CRLF}`;
2220

2321
for (var i = 0; i < len; i++) {

benchmark/http/check_invalid_header_char.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,7 @@ const bench = common.createBenchmark(main, {
3030
n: [1e6],
3131
});
3232

33-
function main(conf) {
34-
const n = +conf.n;
35-
const key = conf.key;
36-
33+
function main({ n, key }) {
3734
bench.start();
3835
for (var i = 0; i < n; i++) {
3936
_checkInvalidHeaderChar(key);

benchmark/http/check_is_http_token.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,7 @@ const bench = common.createBenchmark(main, {
4040
n: [1e6],
4141
});
4242

43-
function main(conf) {
44-
const n = +conf.n;
45-
const key = conf.key;
46-
43+
function main({ n, key }) {
4744
bench.start();
4845
for (var i = 0; i < n; i++) {
4946
_checkIsHttpToken(key);

benchmark/http/chunked.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ const bench = common.createBenchmark(main, {
1616
c: [100]
1717
});
1818

19-
function main(conf) {
19+
function main({ len, n, c }) {
2020
const http = require('http');
21-
const chunk = Buffer.alloc(conf.len, '8');
21+
const chunk = Buffer.alloc(len, '8');
2222

2323
const server = http.createServer(function(req, res) {
2424
function send(left) {
@@ -28,12 +28,12 @@ function main(conf) {
2828
send(left - 1);
2929
}, 0);
3030
}
31-
send(conf.n);
31+
send(n);
3232
});
3333

3434
server.listen(common.PORT, function() {
3535
bench.http({
36-
connections: conf.c
36+
connections: c
3737
}, function() {
3838
server.close();
3939
});

benchmark/http/client-request-body.js

+3-6
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ const bench = common.createBenchmark(main, {
1111
method: ['write', 'end']
1212
});
1313

14-
function main(conf) {
15-
const dur = +conf.dur;
16-
const len = +conf.len;
17-
14+
function main({ dur, len, type, method }) {
1815
var encoding;
1916
var chunk;
20-
switch (conf.type) {
17+
switch (type) {
2118
case 'buf':
2219
chunk = Buffer.alloc(len, 'x');
2320
break;
@@ -55,7 +52,7 @@ function main(conf) {
5552
pummel(); // Line up next request.
5653
res.resume();
5754
});
58-
if (conf.method === 'write') {
55+
if (method === 'write') {
5956
req.write(chunk, encoding);
6057
req.end();
6158
} else {

benchmark/http/cluster.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ if (cluster.isMaster) {
1515
require('../fixtures/simple-http-server.js').listen(port);
1616
}
1717

18-
function main(conf) {
18+
function main({ type, len, c }) {
1919
process.env.PORT = PORT;
2020
var workers = 0;
2121
const w1 = cluster.fork();
@@ -27,11 +27,11 @@ function main(conf) {
2727
return;
2828

2929
setTimeout(function() {
30-
const path = `/${conf.type}/${conf.len}`;
30+
const path = `/${type}/${len}`;
3131

3232
bench.http({
3333
path: path,
34-
connections: conf.c
34+
connections: c
3535
}, function() {
3636
w1.destroy();
3737
w2.destroy();

benchmark/http/create-clientrequest.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ const bench = common.createBenchmark(main, {
88
n: [1e6]
99
});
1010

11-
function main(conf) {
12-
const len = +conf.len;
13-
const n = +conf.n;
14-
11+
function main({ len, n }) {
1512
const path = '/'.repeat(len);
1613
const opts = { path: path, createConnection: function() {} };
1714

benchmark/http/end-vs-write-end.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@ const bench = common.createBenchmark(main, {
1717
method: ['write', 'end']
1818
});
1919

20-
function main(conf) {
20+
function main({ len, type, method, c }) {
2121
const http = require('http');
2222
var chunk;
23-
const len = conf.len;
24-
switch (conf.type) {
23+
switch (type) {
2524
case 'buf':
2625
chunk = Buffer.alloc(len, 'x');
2726
break;
@@ -42,15 +41,15 @@ function main(conf) {
4241
res.end(chunk);
4342
}
4443

45-
const method = conf.method === 'write' ? write : end;
44+
const fn = method === 'write' ? write : end;
4645

4746
const server = http.createServer(function(req, res) {
48-
method(res);
47+
fn(res);
4948
});
5049

5150
server.listen(common.PORT, function() {
5251
bench.http({
53-
connections: conf.c
52+
connections: c
5453
}, function() {
5554
server.close();
5655
});

benchmark/http/simple.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@ const bench = common.createBenchmark(main, {
1212
res: ['normal', 'setHeader', 'setHeaderWH']
1313
});
1414

15-
function main(conf) {
15+
function main({ type, len, chunks, c, chunkedEnc, res }) {
1616
process.env.PORT = PORT;
1717
var server = require('../fixtures/simple-http-server.js')
1818
.listen(PORT)
1919
.on('listening', function() {
20-
const path =
21-
`/${conf.type}/${conf.len}/${conf.chunks}/${conf.res}/${conf.chunkedEnc}`;
20+
const path = `/${type}/${len}/${chunks}/${res}/${chunkedEnc}`;
2221

2322
bench.http({
2423
path: path,
25-
connections: conf.c
24+
connections: c
2625
}, function() {
2726
server.close();
2827
});

0 commit comments

Comments
 (0)