benchmark: use let instead of var in zlib

PR-URL: https://github.com/nodejs/node/pull/31794
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
Daniele Belardi 2020-02-14 14:59:09 +01:00 committed by Anna Henningsen
parent 806899fdba
commit 75aaf7496e
No known key found for this signature in database
GPG Key ID: A94130F0BFC8EBE9
2 changed files with 14 additions and 11 deletions

View File

@ -15,17 +15,16 @@ function main({ n, type, options }) {
const fn = zlib[`create${type}`];
if (typeof fn !== 'function')
throw new Error('Invalid zlib type');
var i = 0;
if (options === 'true') {
const opts = {};
bench.start();
for (; i < n; ++i)
for (let i = 0; i < n; ++i)
fn(opts);
bench.end(n);
} else {
bench.start();
for (; i < n; ++i)
for (let i = 0; i < n; ++i)
fn();
bench.end(n);
}

View File

@ -13,11 +13,11 @@ function main({ n, method, inputLen }) {
method = method || 'deflate';
const chunk = Buffer.alloc(inputLen, 'a');
var i = 0;
switch (method) {
// Performs `n` writes for a single deflate stream
case 'createDeflate':
var deflater = zlib.createDeflate();
case 'createDeflate': {
let i = 0;
const deflater = zlib.createDeflate();
deflater.resume();
deflater.on('finish', () => {
bench.end(n);
@ -30,9 +30,11 @@ function main({ n, method, inputLen }) {
deflater.write(chunk, next);
})();
break;
}
// Performs `n` single deflate operations
case 'deflate':
var deflate = zlib.deflate;
case 'deflate': {
let i = 0;
const deflate = zlib.deflate;
bench.start();
(function next(err, result) {
if (i++ === n)
@ -40,14 +42,16 @@ function main({ n, method, inputLen }) {
deflate(chunk, next);
})();
break;
}
// Performs `n` single deflateSync operations
case 'deflateSync':
var deflateSync = zlib.deflateSync;
case 'deflateSync': {
const deflateSync = zlib.deflateSync;
bench.start();
for (; i < n; ++i)
for (let i = 0; i < n; ++i)
deflateSync(chunk);
bench.end(n);
break;
}
default:
throw new Error('Unsupported deflate method');
}