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 <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
  • Loading branch information
dnlup authored and addaleax committed Mar 30, 2020
1 parent d831665 commit b556670
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 b556670

Please sign in to comment.