Skip to content

Commit

Permalink
benchmark: use let instead of var
Browse files Browse the repository at this point in the history
Use `let` in module, napi, net, os, path, process, querystring, streams
and string_decoder.

PR-URL: #31592
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
dnlup authored and codebytere committed Mar 17, 2020
1 parent 6e54536 commit 8538494
Show file tree
Hide file tree
Showing 30 changed files with 75 additions and 80 deletions.
5 changes: 2 additions & 3 deletions benchmark/module/module-loader-deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,13 @@ function main({ ext, cache, files }) {
}

function measureDir(cache, files) {
var i;
if (cache) {
for (i = 0; i <= files; i++) {
for (let i = 0; i <= files; i++) {
require(`${benchmarkDirectory}/${i}`);
}
}
bench.start();
for (i = 0; i <= files; i++) {
for (let i = 0; i <= files; i++) {
require(`${benchmarkDirectory}/${i}`);
}
bench.end(files);
Expand Down
7 changes: 3 additions & 4 deletions benchmark/module/module-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ function main({ n, name, cache, files, dir }) {
}

function measureDir(n, cache, files, name) {
var i;
if (cache) {
for (i = 0; i <= files; i++) {
for (let i = 0; i <= files; i++) {
require(`${benchmarkDirectory}${i}${name}`);
}
}
bench.start();
for (i = 0; i <= files; i++) {
for (var j = 0; j < n; j++)
for (let i = 0; i <= files; i++) {
for (let j = 0; j < n; j++)
require(`${benchmarkDirectory}${i}${name}`);
// Pretend mixed input (otherwise the results are less representative due to
// highly specialized code).
Expand Down
2 changes: 1 addition & 1 deletion benchmark/napi/function_args/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function main({ n, engine, type }) {
const args = generateArgs(type);

bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
fn.apply(null, args);
}
bench.end(n);
Expand Down
4 changes: 2 additions & 2 deletions benchmark/napi/function_call/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ try {
}
const napi = napi_binding.hello;

var c = 0;
let c = 0;
function js() {
return c++;
}
Expand All @@ -44,7 +44,7 @@ const bench = common.createBenchmark(main, {
function main({ n, type }) {
const fn = type === 'cxx' ? cxx : type === 'napi' ? napi : js;
bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
fn();
}
bench.end(n);
Expand Down
4 changes: 2 additions & 2 deletions benchmark/net/net-c2s-cork.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const bench = common.createBenchmark(main, {
dur: [5],
});

var chunk;
var encoding;
let chunk;
let encoding;

function main({ dur, len, type }) {
switch (type) {
Expand Down
4 changes: 2 additions & 2 deletions benchmark/net/net-c2s.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const bench = common.createBenchmark(main, {
dur: [5],
});

var chunk;
var encoding;
let chunk;
let encoding;

function main({ dur, len, type }) {
switch (type) {
Expand Down
4 changes: 2 additions & 2 deletions benchmark/net/net-pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ const bench = common.createBenchmark(main, {
dur: [5],
});

var chunk;
var encoding;
let chunk;
let encoding;

function main({ dur, len, type }) {
switch (type) {
Expand Down
12 changes: 6 additions & 6 deletions benchmark/net/net-s2c.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ const bench = common.createBenchmark(main, {
dur: [5]
});

var chunk;
var encoding;
var recvbuf;
var received = 0;
let chunk;
let encoding;
let recvbuf;
let received = 0;

function main({ dur, sendchunklen, type, recvbuflen, recvbufgenfn }) {
if (isFinite(recvbuflen) && recvbuflen > 0)
Expand All @@ -38,8 +38,8 @@ function main({ dur, sendchunklen, type, recvbuflen, recvbufgenfn }) {
}

const reader = new Reader();
var writer;
var socketOpts;
let writer;
let socketOpts;
if (recvbuf === undefined) {
writer = new Writer();
socketOpts = { port: PORT };
Expand Down
4 changes: 2 additions & 2 deletions benchmark/net/net-wrap-js-stream-passthrough.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const bench = common.createBenchmark(main, {
flags: ['--expose-internals']
});

var chunk;
var encoding;
let chunk;
let encoding;

function main({ dur, len, type }) {
// Can only require internals inside main().
Expand Down
8 changes: 4 additions & 4 deletions benchmark/net/tcp-raw-c2s.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function main({ dur, len, type }) {
const PORT = common.PORT;

const serverHandle = new TCP(TCPConstants.SERVER);
var err = serverHandle.bind('127.0.0.1', PORT);
let err = serverHandle.bind('127.0.0.1', PORT);
if (err)
fail(err, 'bind');

Expand All @@ -38,7 +38,7 @@ function main({ dur, len, type }) {

// The meat of the benchmark is right here:
bench.start();
var bytes = 0;
let bytes = 0;

setTimeout(() => {
// report in Gb/sec
Expand Down Expand Up @@ -67,7 +67,7 @@ function main({ dur, len, type }) {
}

function client(type, len) {
var chunk;
let chunk;
switch (type) {
case 'buf':
chunk = Buffer.alloc(len, 'x');
Expand Down Expand Up @@ -102,7 +102,7 @@ function main({ dur, len, type }) {
function write() {
const writeReq = new WriteWrap();
writeReq.oncomplete = afterWrite;
var err;
let err;
switch (type) {
case 'buf':
err = clientHandle.writeBuffer(writeReq, chunk);
Expand Down
8 changes: 4 additions & 4 deletions benchmark/net/tcp-raw-pipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function main({ dur, len, type }) {

// Server
const serverHandle = new TCP(TCPConstants.SERVER);
var err = serverHandle.bind('127.0.0.1', PORT);
let err = serverHandle.bind('127.0.0.1', PORT);
if (err)
fail(err, 'bind');

Expand Down Expand Up @@ -66,7 +66,7 @@ function main({ dur, len, type }) {
};

// Client
var chunk;
let chunk;
switch (type) {
case 'buf':
chunk = Buffer.alloc(len, 'x');
Expand All @@ -83,7 +83,7 @@ function main({ dur, len, type }) {

const clientHandle = new TCP(TCPConstants.SOCKET);
const connectReq = new TCPConnectWrap();
var bytes = 0;
let bytes = 0;

err = clientHandle.connect(connectReq, '127.0.0.1', PORT);
if (err)
Expand Down Expand Up @@ -118,7 +118,7 @@ function main({ dur, len, type }) {
function write() {
const writeReq = new WriteWrap();
writeReq.oncomplete = afterWrite;
var err;
let err;
switch (type) {
case 'buf':
err = clientHandle.writeBuffer(writeReq, chunk);
Expand Down
8 changes: 4 additions & 4 deletions benchmark/net/tcp-raw-s2c.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function main({ dur, len, type }) {
const PORT = common.PORT;

const serverHandle = new TCP(TCPConstants.SERVER);
var err = serverHandle.bind('127.0.0.1', PORT);
let err = serverHandle.bind('127.0.0.1', PORT);
if (err)
fail(err, 'bind');

Expand All @@ -38,7 +38,7 @@ function main({ dur, len, type }) {
if (err)
fail(err, 'connect');

var chunk;
let chunk;
switch (type) {
case 'buf':
chunk = Buffer.alloc(len, 'x');
Expand All @@ -62,7 +62,7 @@ function main({ dur, len, type }) {
const writeReq = new WriteWrap();
writeReq.async = false;
writeReq.oncomplete = afterWrite;
var err;
let err;
switch (type) {
case 'buf':
err = clientHandle.writeBuffer(writeReq, chunk);
Expand Down Expand Up @@ -108,7 +108,7 @@ function main({ dur, len, type }) {
fail(err, 'connect');

connectReq.oncomplete = function() {
var bytes = 0;
let bytes = 0;
clientHandle.onread = function(buffer) {
// We're not expecting to ever get an EOF from the client.
// Just lots of data forever.
Expand Down
2 changes: 1 addition & 1 deletion benchmark/path/basename-posix.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const bench = common.createBenchmark(main, {
});

function main({ n, pathext }) {
var ext;
let ext;
const extIdx = pathext.indexOf('|');
if (extIdx !== -1) {
ext = pathext.slice(extIdx + 1);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/path/basename-win32.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const bench = common.createBenchmark(main, {
});

function main({ n, pathext }) {
var ext;
let ext;
const extIdx = pathext.indexOf('|');
if (extIdx !== -1) {
ext = pathext.slice(extIdx + 1);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/path/relative-posix.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const bench = common.createBenchmark(main, {
});

function main({ n, paths }) {
var to = '';
let to = '';
const delimIdx = paths.indexOf('|');
if (delimIdx > -1) {
to = paths.slice(delimIdx + 1);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/path/relative-win32.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const bench = common.createBenchmark(main, {
});

function main({ n, paths }) {
var to = '';
let to = '';
const delimIdx = paths.indexOf('|');
if (delimIdx > -1) {
to = paths.slice(delimIdx + 1);
Expand Down
9 changes: 4 additions & 5 deletions benchmark/process/bench-hrtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,26 @@ const bench = common.createBenchmark(main, {

function main({ n, type }) {
const hrtime = process.hrtime;
var noDead = type === 'bigint' ? hrtime.bigint() : hrtime();
var i;
let noDead = type === 'bigint' ? hrtime.bigint() : hrtime();

switch (type) {
case 'raw':
bench.start();
for (i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
noDead = hrtime();
}
bench.end(n);
break;
case 'diff':
bench.start();
for (i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
noDead = hrtime(noDead);
}
bench.end(n);
break;
case 'bigint':
bench.start();
for (i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
noDead = hrtime.bigint();
}
bench.end(n);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/process/next-tick-breadth-args.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const bench = common.createBenchmark(main, {
});

function main({ n }) {
var j = 0;
let j = 0;

function cb1(arg1) {
j++;
Expand Down
2 changes: 1 addition & 1 deletion benchmark/process/next-tick-breadth.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const bench = common.createBenchmark(main, {
});

function main({ n }) {
var j = 0;
let j = 0;

function cb() {
j++;
Expand Down
2 changes: 1 addition & 1 deletion benchmark/process/queue-microtask-breadth.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const bench = common.createBenchmark(main, {
});

function main({ n }) {
var j = 0;
let j = 0;

function cb() {
j++;
Expand Down
10 changes: 5 additions & 5 deletions benchmark/querystring/querystring-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ const bench = common.createBenchmark(main, {

function main({ type, n }) {
const input = inputs[type];
var i;

// Execute the function a "sufficient" number of times before the timed
// loop to ensure the function is optimized just once.
if (type === 'multicharsep') {
for (i = 0; i < n; i += 1)
for (let i = 0; i < n; i += 1)
querystring.parse(input, '&&&&&&&&&&');

bench.start();
for (i = 0; i < n; i += 1)
for (let i = 0; i < n; i += 1)
querystring.parse(input, '&&&&&&&&&&');
bench.end(n);
} else {
for (i = 0; i < n; i += 1)
for (let i = 0; i < n; i += 1)
querystring.parse(input);

bench.start();
for (i = 0; i < n; i += 1)
for (let i = 0; i < n; i += 1)
querystring.parse(input);
bench.end(n);
}
Expand Down
Loading

0 comments on commit 8538494

Please sign in to comment.