Skip to content

Commit 4ee5665

Browse files
dnluptargos
authored andcommitted
benchmark: use let instead of var in dgram
PR-URL: #31175 Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: David Carlier <[email protected]>
1 parent 18cd002 commit 4ee5665

File tree

5 files changed

+17
-18
lines changed

5 files changed

+17
-18
lines changed

benchmark/dgram/array-vs-concat.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ const bench = common.createBenchmark(main, {
1818

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

2525
// Server
26-
var sent = 0;
26+
let sent = 0;
2727
const socket = dgram.createSocket('udp4');
2828
const onsend = type === 'concat' ? onsendConcat : onsendMulti;
2929

@@ -32,7 +32,7 @@ function main({ dur, len, num, type, chunks }) {
3232
// The setImmediate() is necessary to have event loop progress on OSes
3333
// that only perform synchronous I/O on nonblocking UDP sockets.
3434
setImmediate(() => {
35-
for (var i = 0; i < num; i++) {
35+
for (let i = 0; i < num; i++) {
3636
socket.send(Buffer.concat(chunk), PORT, '127.0.0.1', onsend);
3737
}
3838
});
@@ -44,7 +44,7 @@ function main({ dur, len, num, type, chunks }) {
4444
// The setImmediate() is necessary to have event loop progress on OSes
4545
// that only perform synchronous I/O on nonblocking UDP sockets.
4646
setImmediate(() => {
47-
for (var i = 0; i < num; i++) {
47+
for (let i = 0; i < num; i++) {
4848
socket.send(chunk, PORT, '127.0.0.1', onsend);
4949
}
5050
});

benchmark/dgram/bind-params.js

+3-4
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,18 @@ const noop = () => {};
1515
function main({ n, port, address }) {
1616
port = port === 'true' ? 0 : undefined;
1717
address = address === 'true' ? '0.0.0.0' : undefined;
18-
var i;
1918

2019
if (port !== undefined && address !== undefined) {
2120
bench.start();
22-
for (i = 0; i < n; i++) {
21+
for (let i = 0; i < n; i++) {
2322
dgram.createSocket('udp4').bind(port, address)
2423
.on('error', noop)
2524
.unref();
2625
}
2726
bench.end(n);
2827
} else if (port !== undefined) {
2928
bench.start();
30-
for (i = 0; i < n; i++) {
29+
for (let i = 0; i < n; i++) {
3130
dgram.createSocket('udp4')
3231
.bind(port)
3332
.on('error', noop)
@@ -36,7 +35,7 @@ function main({ n, port, address }) {
3635
bench.end(n);
3736
} else if (port === undefined && address === undefined) {
3837
bench.start();
39-
for (i = 0; i < n; i++) {
38+
for (let i = 0; i < n; i++) {
4039
dgram.createSocket('udp4')
4140
.bind()
4241
.on('error', noop)

benchmark/dgram/multi-buffer.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,19 @@ const bench = common.createBenchmark(main, {
1818

1919
function main({ dur, len, num, type, chunks }) {
2020
const chunk = [];
21-
for (var i = 0; i < chunks; i++) {
21+
for (let i = 0; i < chunks; i++) {
2222
chunk.push(Buffer.allocUnsafe(Math.round(len / chunks)));
2323
}
24-
var sent = 0;
25-
var received = 0;
24+
let sent = 0;
25+
let received = 0;
2626
const socket = dgram.createSocket('udp4');
2727

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

benchmark/dgram/offset-length.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ const bench = common.createBenchmark(main, {
1717

1818
function main({ dur, len, num, type }) {
1919
const chunk = Buffer.allocUnsafe(len);
20-
var sent = 0;
21-
var received = 0;
20+
let sent = 0;
21+
let received = 0;
2222
const socket = dgram.createSocket('udp4');
2323

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

benchmark/dgram/single-buffer.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,16 @@ const bench = common.createBenchmark(main, {
1717

1818
function main({ dur, len, num, type }) {
1919
const chunk = Buffer.allocUnsafe(len);
20-
var sent = 0;
21-
var received = 0;
20+
let sent = 0;
21+
let received = 0;
2222
const socket = dgram.createSocket('udp4');
2323

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

0 commit comments

Comments
 (0)