Skip to content

Commit

Permalink
benchmark: (dgram) use destructuring
Browse files Browse the repository at this point in the history
PR-URL: #18250
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
BridgeAR authored and evanlucas committed Jan 30, 2018
1 parent e19c77b commit cd9bc8b
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 84 deletions.
26 changes: 4 additions & 22 deletions benchmark/dgram/array-vs-concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict';

const common = require('../common.js');
const dgram = require('dgram');
const PORT = common.PORT;

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

var dur;
var len;
var num;
var type;
var chunk;
var chunks;

function main(conf) {
dur = +conf.dur;
len = +conf.len;
num = +conf.num;
type = conf.type;
chunks = +conf.chunks;

chunk = [];
function main({ dur, len, num, type, chunks }) {
const chunk = [];
for (var i = 0; i < chunks; i++) {
chunk.push(Buffer.allocUnsafe(Math.round(len / chunks)));
}

server();
}

const dgram = require('dgram');

function server() {
// Server
var sent = 0;
const socket = dgram.createSocket('udp4');

const onsend = type === 'concat' ? onsendConcat : onsendMulti;

function onsendConcat() {
Expand Down
7 changes: 3 additions & 4 deletions benchmark/dgram/bind-params.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ const configs = {
const bench = common.createBenchmark(main, configs);
const noop = () => {};

function main(conf) {
const n = +conf.n;
const port = conf.port === 'true' ? 0 : undefined;
const address = conf.address === 'true' ? '0.0.0.0' : undefined;
function main({ n, port, address }) {
port = port === 'true' ? 0 : undefined;
address = address === 'true' ? '0.0.0.0' : undefined;

if (port !== undefined && address !== undefined) {
bench.start();
Expand Down
25 changes: 3 additions & 22 deletions benchmark/dgram/multi-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict';

const common = require('../common.js');
const dgram = require('dgram');
const PORT = common.PORT;

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

var dur;
var len;
var num;
var type;
var chunk;
var chunks;

function main(conf) {
dur = +conf.dur;
len = +conf.len;
num = +conf.num;
type = conf.type;
chunks = +conf.chunks;

chunk = [];
function main({ dur, len, num, type, chunks }) {
const chunk = [];
for (var i = 0; i < chunks; i++) {
chunk.push(Buffer.allocUnsafe(Math.round(len / chunks)));
}

server();
}

const dgram = require('dgram');

function server() {
var sent = 0;
var received = 0;
const socket = dgram.createSocket('udp4');
Expand Down
21 changes: 3 additions & 18 deletions benchmark/dgram/offset-length.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict';

const common = require('../common.js');
const dgram = require('dgram');
const PORT = common.PORT;

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

var dur;
var len;
var num;
var type;
var chunk;

function main(conf) {
dur = +conf.dur;
len = +conf.len;
num = +conf.num;
type = conf.type;
chunk = Buffer.allocUnsafe(len);
server();
}

const dgram = require('dgram');

function server() {
function main({ dur, len, num, type }) {
const chunk = Buffer.allocUnsafe(len);
var sent = 0;
var received = 0;
const socket = dgram.createSocket('udp4');
Expand Down
21 changes: 3 additions & 18 deletions benchmark/dgram/single-buffer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
'use strict';

const common = require('../common.js');
const dgram = require('dgram');
const PORT = common.PORT;

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

var dur;
var len;
var num;
var type;
var chunk;

function main(conf) {
dur = +conf.dur;
len = +conf.len;
num = +conf.num;
type = conf.type;
chunk = Buffer.allocUnsafe(len);
server();
}

const dgram = require('dgram');

function server() {
function main({ dur, len, num, type }) {
const chunk = Buffer.allocUnsafe(len);
var sent = 0;
var received = 0;
const socket = dgram.createSocket('udp4');
Expand Down

0 comments on commit cd9bc8b

Please sign in to comment.