Skip to content

Commit

Permalink
benchmark: use let instead of var in zlib
Browse files Browse the repository at this point in the history
PR-URL: #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>
  • Loading branch information
dnlup authored and targos committed Apr 28, 2020
1 parent f13ecd8 commit daf6e17
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
5 changes: 2 additions & 3 deletions benchmark/zlib/creation.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
20 changes: 12 additions & 8 deletions benchmark/zlib/deflate.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -30,24 +30,28 @@ 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)
return bench.end(n);
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');
}
Expand Down

0 comments on commit daf6e17

Please sign in to comment.