Skip to content

Commit cd9bc8b

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

File tree

5 files changed

+16
-84
lines changed

5 files changed

+16
-84
lines changed

benchmark/dgram/array-vs-concat.js

+4-22
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
'use strict';
33

44
const common = require('../common.js');
5+
const dgram = require('dgram');
56
const PORT = common.PORT;
67

78
// `num` is the number of send requests to queue up each time.
@@ -15,34 +16,15 @@ const bench = common.createBenchmark(main, {
1516
dur: [5]
1617
});
1718

18-
var dur;
19-
var len;
20-
var num;
21-
var type;
22-
var chunk;
23-
var chunks;
24-
25-
function main(conf) {
26-
dur = +conf.dur;
27-
len = +conf.len;
28-
num = +conf.num;
29-
type = conf.type;
30-
chunks = +conf.chunks;
31-
32-
chunk = [];
19+
function main({ dur, len, num, type, chunks }) {
20+
const chunk = [];
3321
for (var i = 0; i < chunks; i++) {
3422
chunk.push(Buffer.allocUnsafe(Math.round(len / chunks)));
3523
}
3624

37-
server();
38-
}
39-
40-
const dgram = require('dgram');
41-
42-
function server() {
25+
// Server
4326
var sent = 0;
4427
const socket = dgram.createSocket('udp4');
45-
4628
const onsend = type === 'concat' ? onsendConcat : onsendMulti;
4729

4830
function onsendConcat() {

benchmark/dgram/bind-params.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ const configs = {
1212
const bench = common.createBenchmark(main, configs);
1313
const noop = () => {};
1414

15-
function main(conf) {
16-
const n = +conf.n;
17-
const port = conf.port === 'true' ? 0 : undefined;
18-
const address = conf.address === 'true' ? '0.0.0.0' : undefined;
15+
function main({ n, port, address }) {
16+
port = port === 'true' ? 0 : undefined;
17+
address = address === 'true' ? '0.0.0.0' : undefined;
1918

2019
if (port !== undefined && address !== undefined) {
2120
bench.start();

benchmark/dgram/multi-buffer.js

+3-22
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
'use strict';
33

44
const common = require('../common.js');
5+
const dgram = require('dgram');
56
const PORT = common.PORT;
67

78
// `num` is the number of send requests to queue up each time.
@@ -15,31 +16,11 @@ const bench = common.createBenchmark(main, {
1516
dur: [5]
1617
});
1718

18-
var dur;
19-
var len;
20-
var num;
21-
var type;
22-
var chunk;
23-
var chunks;
24-
25-
function main(conf) {
26-
dur = +conf.dur;
27-
len = +conf.len;
28-
num = +conf.num;
29-
type = conf.type;
30-
chunks = +conf.chunks;
31-
32-
chunk = [];
19+
function main({ dur, len, num, type, chunks }) {
20+
const chunk = [];
3321
for (var i = 0; i < chunks; i++) {
3422
chunk.push(Buffer.allocUnsafe(Math.round(len / chunks)));
3523
}
36-
37-
server();
38-
}
39-
40-
const dgram = require('dgram');
41-
42-
function server() {
4324
var sent = 0;
4425
var received = 0;
4526
const socket = dgram.createSocket('udp4');

benchmark/dgram/offset-length.js

+3-18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
'use strict';
33

44
const common = require('../common.js');
5+
const dgram = require('dgram');
56
const PORT = common.PORT;
67

78
// `num` is the number of send requests to queue up each time.
@@ -14,24 +15,8 @@ const bench = common.createBenchmark(main, {
1415
dur: [5]
1516
});
1617

17-
var dur;
18-
var len;
19-
var num;
20-
var type;
21-
var chunk;
22-
23-
function main(conf) {
24-
dur = +conf.dur;
25-
len = +conf.len;
26-
num = +conf.num;
27-
type = conf.type;
28-
chunk = Buffer.allocUnsafe(len);
29-
server();
30-
}
31-
32-
const dgram = require('dgram');
33-
34-
function server() {
18+
function main({ dur, len, num, type }) {
19+
const chunk = Buffer.allocUnsafe(len);
3520
var sent = 0;
3621
var received = 0;
3722
const socket = dgram.createSocket('udp4');

benchmark/dgram/single-buffer.js

+3-18
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
'use strict';
33

44
const common = require('../common.js');
5+
const dgram = require('dgram');
56
const PORT = common.PORT;
67

78
// `num` is the number of send requests to queue up each time.
@@ -14,24 +15,8 @@ const bench = common.createBenchmark(main, {
1415
dur: [5]
1516
});
1617

17-
var dur;
18-
var len;
19-
var num;
20-
var type;
21-
var chunk;
22-
23-
function main(conf) {
24-
dur = +conf.dur;
25-
len = +conf.len;
26-
num = +conf.num;
27-
type = conf.type;
28-
chunk = Buffer.allocUnsafe(len);
29-
server();
30-
}
31-
32-
const dgram = require('dgram');
33-
34-
function server() {
18+
function main({ dur, len, num, type }) {
19+
const chunk = Buffer.allocUnsafe(len);
3520
var sent = 0;
3621
var received = 0;
3722
const socket = dgram.createSocket('udp4');

0 commit comments

Comments
 (0)