Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

benchmark: use let instead of var #31592

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions benchmark/module/module-loader-deep.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function main({ ext, cache, files }) {
`${benchmarkDirectory}/a.js`,
'module.exports = {};'
);
for (var i = 0; i <= files; i++) {
for (let i = 0; i <= files; i++) {
fs.mkdirSync(`${benchmarkDirectory}/${i}`);
fs.writeFileSync(
`${benchmarkDirectory}/${i}/package.json`,
Expand All @@ -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
9 changes: 4 additions & 5 deletions benchmark/module/module-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const bench = common.createBenchmark(main, {
function main({ n, name, cache, files, dir }) {
tmpdir.refresh();
fs.mkdirSync(benchmarkDirectory);
for (var i = 0; i <= files; i++) {
for (let i = 0; i <= files; i++) {
fs.mkdirSync(`${benchmarkDirectory}${i}`);
fs.writeFileSync(
`${benchmarkDirectory}${i}/package.json`,
Expand All @@ -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/os/cpus.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const bench = common.createBenchmark(main, {

function main({ n }) {
bench.start();
for (var i = 0; i < n; ++i)
for (let i = 0; i < n; ++i)
cpus();
bench.end(n);
}
2 changes: 1 addition & 1 deletion benchmark/os/loadavg.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const bench = common.createBenchmark(main, {

function main({ n }) {
bench.start();
for (var i = 0; i < n; ++i)
for (let i = 0; i < n; ++i)
loadavg();
bench.end(n);
}
2 changes: 1 addition & 1 deletion benchmark/os/networkInterfaces.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const bench = common.createBenchmark(main, {

function main({ n }) {
bench.start();
for (var i = 0; i < n; ++i)
for (let i = 0; i < n; ++i)
networkInterfaces();
bench.end(n);
}
4 changes: 2 additions & 2 deletions benchmark/path/basename-posix.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ 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);
pathext = pathext.slice(0, extIdx);
}

bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
posix.basename(i % 3 === 0 ? `${pathext}${i}` : pathext, ext);
}
bench.end(n);
Expand Down
4 changes: 2 additions & 2 deletions benchmark/path/basename-win32.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,15 @@ 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);
pathext = pathext.slice(0, extIdx);
}

bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
win32.basename(i % 3 === 0 ? `${pathext}${i}` : pathext, ext);
}
bench.end(n);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/path/dirname-posix.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const bench = common.createBenchmark(main, {

function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
posix.dirname(i % 3 === 0 ? `${path}${i}` : path);
}
bench.end(n);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/path/dirname-win32.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const bench = common.createBenchmark(main, {

function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
win32.dirname(i % 3 === 0 ? `${path}${i}` : path);
}
bench.end(n);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/path/extname-posix.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const bench = common.createBenchmark(main, {

function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
posix.extname(i % 3 === 0 ? `${path}${i}` : path);
}
bench.end(n);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/path/extname-win32.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const bench = common.createBenchmark(main, {

function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
win32.extname(i % 3 === 0 ? `${path}${i}` : path);
}
bench.end(n);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/path/format-posix.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function main({ n, props }) {
};

bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
obj.base = `a${i}${props[2] || ''}`;
obj.name = `a${i}${props[4] || ''}`;
posix.format(obj);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/path/format-win32.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function main({ n, props }) {
};

bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
obj.base = `a${i}${props[2] || ''}`;
obj.name = `a${i}${props[4] || ''}`;
win32.format(obj);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/path/isAbsolute-posix.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const bench = common.createBenchmark(main, {

function main({ n, path }) {
bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
posix.isAbsolute(i % 3 === 0 ? `${path}${i}` : path);
}
bench.end(n);
Expand Down
2 changes: 1 addition & 1 deletion benchmark/path/isAbsolute-win32.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, path }) {
bench.start();
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
win32.isAbsolute(i % 3 === 0 ? `${path}${i}` : path);
}
bench.end(n);
Expand Down
Loading