Skip to content
Permalink
Browse files

benchmark: use let instead of var in dgram

PR-URL: #31175
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: David Carlier <devnexen@gmail.com>
  • Loading branch information
dnlup authored and Trott committed Jan 3, 2020
1 parent 783f8c6 commit 57a1ca99abea8a58fc9870896fc3aca374cdb6cc
@@ -18,12 +18,12 @@ const bench = common.createBenchmark(main, {

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

// Server
var sent = 0;
let sent = 0;
const socket = dgram.createSocket('udp4');
const onsend = type === 'concat' ? onsendConcat : onsendMulti;

@@ -32,7 +32,7 @@ function main({ dur, len, num, type, chunks }) {
// The setImmediate() is necessary to have event loop progress on OSes
// that only perform synchronous I/O on nonblocking UDP sockets.
setImmediate(() => {
for (var i = 0; i < num; i++) {
for (let i = 0; i < num; i++) {
socket.send(Buffer.concat(chunk), PORT, '127.0.0.1', onsend);
}
});
@@ -44,7 +44,7 @@ function main({ dur, len, num, type, chunks }) {
// The setImmediate() is necessary to have event loop progress on OSes
// that only perform synchronous I/O on nonblocking UDP sockets.
setImmediate(() => {
for (var i = 0; i < num; i++) {
for (let i = 0; i < num; i++) {
socket.send(chunk, PORT, '127.0.0.1', onsend);
}
});
@@ -15,19 +15,18 @@ const noop = () => {};
function main({ n, port, address }) {
port = port === 'true' ? 0 : undefined;
address = address === 'true' ? '0.0.0.0' : undefined;
var i;

if (port !== undefined && address !== undefined) {
bench.start();
for (i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
dgram.createSocket('udp4').bind(port, address)
.on('error', noop)
.unref();
}
bench.end(n);
} else if (port !== undefined) {
bench.start();
for (i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
dgram.createSocket('udp4')
.bind(port)
.on('error', noop)
@@ -36,7 +35,7 @@ function main({ n, port, address }) {
bench.end(n);
} else if (port === undefined && address === undefined) {
bench.start();
for (i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
dgram.createSocket('udp4')
.bind()
.on('error', noop)
@@ -18,19 +18,19 @@ const bench = common.createBenchmark(main, {

function main({ dur, len, num, type, chunks }) {
const chunk = [];
for (var i = 0; i < chunks; i++) {
for (let i = 0; i < chunks; i++) {
chunk.push(Buffer.allocUnsafe(Math.round(len / chunks)));
}
var sent = 0;
var received = 0;
let sent = 0;
let received = 0;
const socket = dgram.createSocket('udp4');

function onsend() {
if (sent++ % num === 0) {
// The setImmediate() is necessary to have event loop progress on OSes
// that only perform synchronous I/O on nonblocking UDP sockets.
setImmediate(() => {
for (var i = 0; i < num; i++) {
for (let i = 0; i < num; i++) {
socket.send(chunk, PORT, '127.0.0.1', onsend);
}
});
@@ -17,16 +17,16 @@ const bench = common.createBenchmark(main, {

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

function onsend() {
if (sent++ % num === 0) {
// The setImmediate() is necessary to have event loop progress on OSes
// that only perform synchronous I/O on nonblocking UDP sockets.
setImmediate(() => {
for (var i = 0; i < num; i++) {
for (let i = 0; i < num; i++) {
socket.send(chunk, 0, chunk.length, PORT, '127.0.0.1', onsend);
}
});
@@ -17,16 +17,16 @@ const bench = common.createBenchmark(main, {

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

function onsend() {
if (sent++ % num === 0) {
// The setImmediate() is necessary to have event loop progress on OSes
// that only perform synchronous I/O on nonblocking UDP sockets.
setImmediate(() => {
for (var i = 0; i < num; i++) {
for (let i = 0; i < num; i++) {
socket.send(chunk, PORT, '127.0.0.1', onsend);
}
});

0 comments on commit 57a1ca9

Please sign in to comment.
You can’t perform that action at this time.