benchmark: use let instead of var

Use `let` in module, napi, net, os, path, process, querystring, streams
and string_decoder.

PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
Daniele Belardi 2020-01-31 16:50:00 +01:00 committed by Shelley Vohr
parent 7173b285e7
commit 0b7579022c
No known key found for this signature in database
GPG Key ID: F13993A75599653C
30 changed files with 75 additions and 80 deletions

View File

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

View File

@ -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).

View File

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

View File

@ -29,7 +29,7 @@ try {
}
const napi = napi_binding.hello;
var c = 0;
let c = 0;
function js() {
return c++;
}
@ -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);

View File

@ -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) {

View File

@ -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) {

View File

@ -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) {

View File

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

View File

@ -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().

View File

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

View File

@ -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');
@ -66,7 +66,7 @@ function main({ dur, len, type }) {
};
// Client
var chunk;
let chunk;
switch (type) {
case 'buf':
chunk = Buffer.alloc(len, 'x');
@ -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)
@ -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);

View File

@ -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');
@ -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');
@ -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);
@ -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.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -6,7 +6,7 @@ const bench = common.createBenchmark(main, {
});
function main({ n }) {
var j = 0;
let j = 0;
function cb1(arg1) {
j++;

View File

@ -6,7 +6,7 @@ const bench = common.createBenchmark(main, {
});
function main({ n }) {
var j = 0;
let j = 0;
function cb() {
j++;

View File

@ -6,7 +6,7 @@ const bench = common.createBenchmark(main, {
});
function main({ n }) {
var j = 0;
let j = 0;
function cb() {
j++;

View File

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

View File

@ -13,14 +13,13 @@ const bench = common.createBenchmark(main, {
});
function main({ n, kind }) {
var i = 0;
switch (kind) {
case 'duplex':
new Duplex({});
new Duplex();
bench.start();
for (; i < n; ++i)
for (let i = 0; i < n; ++i)
new Duplex();
bench.end(n);
break;
@ -29,7 +28,7 @@ function main({ n, kind }) {
new Readable();
bench.start();
for (; i < n; ++i)
for (let i = 0; i < n; ++i)
new Readable();
bench.end(n);
break;
@ -38,7 +37,7 @@ function main({ n, kind }) {
new Writable();
bench.start();
for (; i < n; ++i)
for (let i = 0; i < n; ++i)
new Writable();
bench.end(n);
break;
@ -47,7 +46,7 @@ function main({ n, kind }) {
new Transform();
bench.start();
for (; i < n; ++i)
for (let i = 0; i < n; ++i)
new Transform();
bench.end(n);
break;

View File

@ -12,7 +12,7 @@ function main({ n }) {
const r = new Readable({ objectMode: true });
const w = new Writable({ objectMode: true });
var i = 0;
let i = 0;
r._read = () => r.push(i++ === n ? null : b);
w._write = (data, enc, cb) => cb();

View File

@ -12,7 +12,7 @@ function main({ n }) {
const r = new Readable();
const w = new Writable();
var i = 0;
let i = 0;
r._read = () => r.push(i++ === n ? null : b);
w._write = (data, enc, cb) => cb();

View File

@ -14,8 +14,8 @@ function main({ n }) {
s._read = noop;
bench.start();
for (var k = 0; k < n; ++k) {
for (var i = 0; i < 1e4; ++i)
for (let k = 0; k < n; ++k) {
for (let i = 0; i < 1e4; ++i)
s.push(b);
while (s.read(128));
}

View File

@ -14,8 +14,8 @@ function main({ n }) {
s._read = noop;
bench.start();
for (var k = 0; k < n; ++k) {
for (var i = 0; i < 1e4; ++i)
for (let k = 0; k < n; ++k) {
for (let i = 0; i < 1e4; ++i)
s.push(b);
while (s.read(106));
}

View File

@ -10,14 +10,14 @@ const bench = common.createBenchmark(main, {
function main({ n, type }) {
const s = new Readable();
var data = 'a'.repeat(32);
let data = 'a'.repeat(32);
if (type === 'buffer')
data = Buffer.from(data);
s._read = function() {};
bench.start();
for (var k = 0; k < n; ++k) {
for (var i = 0; i < 1e4; ++i)
for (let k = 0; k < n; ++k) {
for (let i = 0; i < 1e4; ++i)
s.push(data);
while (s.read(32));
}

View File

@ -14,8 +14,8 @@ function main({ n }) {
s._read = noop;
bench.start();
for (var k = 0; k < n; ++k) {
for (var i = 0; i < 1e4; ++i)
for (let k = 0; k < n; ++k) {
for (let i = 0; i < 1e4; ++i)
s.push(b);
while (s.read());
}

View File

@ -14,8 +14,8 @@ function main({ n }) {
s._read = noop;
bench.start();
for (var k = 0; k < n; ++k) {
for (var i = 0; i < 1e4; ++i)
for (let k = 0; k < n; ++k) {
for (let i = 0; i < 1e4; ++i)
s.push(b);
while (s.read(12));
}

View File

@ -14,12 +14,11 @@ const ASC_ALPHA = 'Blueberry jam';
const UTF16_BUF = Buffer.from('Blåbærsyltetøy', 'utf16le');
function main({ encoding, inLen, chunkLen, n }) {
var alpha;
var buf;
let alpha;
let buf;
const chunks = [];
var str = '';
let str = '';
const isBase64 = (encoding === 'base64-ascii' || encoding === 'base64-utf8');
var i;
if (encoding === 'ascii' || encoding === 'base64-ascii')
alpha = ASC_ALPHA;
@ -33,7 +32,7 @@ function main({ encoding, inLen, chunkLen, n }) {
const sd = new StringDecoder(isBase64 ? 'base64' : encoding);
for (i = 0; i < inLen; ++i) {
for (let i = 0; i < inLen; ++i) {
if (i > 0 && (i % chunkLen) === 0 && !isBase64) {
if (alpha) {
chunks.push(Buffer.from(str, encoding));
@ -46,8 +45,8 @@ function main({ encoding, inLen, chunkLen, n }) {
if (alpha)
str += alpha[i % alpha.length];
else {
var start = i;
var end = i + 2;
let start = i;
let end = i + 2;
if (i % 2 !== 0) {
++start;
++end;
@ -77,8 +76,8 @@ function main({ encoding, inLen, chunkLen, n }) {
const nChunks = chunks.length;
bench.start();
for (i = 0; i < n; ++i) {
for (var j = 0; j < nChunks; ++j)
for (let i = 0; i < n; ++i) {
for (let j = 0; j < nChunks; ++j)
sd.write(chunks[j]);
}
bench.end(n);