benchmark: use let instead of var in dgram

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
dnlup 2020-01-03 14:37:27 +01:00 committed by Rich Trott
parent 783f8c626c
commit 57a1ca99ab
5 changed files with 17 additions and 18 deletions

View File

@ -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);
}
});

View File

@ -15,11 +15,10 @@ 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();
@ -27,7 +26,7 @@ function main({ n, port, address }) {
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)

View File

@ -18,11 +18,11 @@ 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() {
@ -30,7 +30,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);
}
});

View File

@ -17,8 +17,8 @@ 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() {
@ -26,7 +26,7 @@ function main({ dur, len, num, type }) {
// 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);
}
});

View File

@ -17,8 +17,8 @@ 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() {
@ -26,7 +26,7 @@ function main({ dur, len, num, type }) {
// 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);
}
});