mirror of https://github.com/nodejs/node.git
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>pull/32563/head
parent
806899fdba
commit
75aaf7496e
|
@ -15,17 +15,16 @@ function main({ n, type, options }) {
|
||||||
const fn = zlib[`create${type}`];
|
const fn = zlib[`create${type}`];
|
||||||
if (typeof fn !== 'function')
|
if (typeof fn !== 'function')
|
||||||
throw new Error('Invalid zlib type');
|
throw new Error('Invalid zlib type');
|
||||||
var i = 0;
|
|
||||||
|
|
||||||
if (options === 'true') {
|
if (options === 'true') {
|
||||||
const opts = {};
|
const opts = {};
|
||||||
bench.start();
|
bench.start();
|
||||||
for (; i < n; ++i)
|
for (let i = 0; i < n; ++i)
|
||||||
fn(opts);
|
fn(opts);
|
||||||
bench.end(n);
|
bench.end(n);
|
||||||
} else {
|
} else {
|
||||||
bench.start();
|
bench.start();
|
||||||
for (; i < n; ++i)
|
for (let i = 0; i < n; ++i)
|
||||||
fn();
|
fn();
|
||||||
bench.end(n);
|
bench.end(n);
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,11 +13,11 @@ function main({ n, method, inputLen }) {
|
||||||
method = method || 'deflate';
|
method = method || 'deflate';
|
||||||
const chunk = Buffer.alloc(inputLen, 'a');
|
const chunk = Buffer.alloc(inputLen, 'a');
|
||||||
|
|
||||||
var i = 0;
|
|
||||||
switch (method) {
|
switch (method) {
|
||||||
// Performs `n` writes for a single deflate stream
|
// Performs `n` writes for a single deflate stream
|
||||||
case 'createDeflate':
|
case 'createDeflate': {
|
||||||
var deflater = zlib.createDeflate();
|
let i = 0;
|
||||||
|
const deflater = zlib.createDeflate();
|
||||||
deflater.resume();
|
deflater.resume();
|
||||||
deflater.on('finish', () => {
|
deflater.on('finish', () => {
|
||||||
bench.end(n);
|
bench.end(n);
|
||||||
|
@ -30,9 +30,11 @@ function main({ n, method, inputLen }) {
|
||||||
deflater.write(chunk, next);
|
deflater.write(chunk, next);
|
||||||
})();
|
})();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
// Performs `n` single deflate operations
|
// Performs `n` single deflate operations
|
||||||
case 'deflate':
|
case 'deflate': {
|
||||||
var deflate = zlib.deflate;
|
let i = 0;
|
||||||
|
const deflate = zlib.deflate;
|
||||||
bench.start();
|
bench.start();
|
||||||
(function next(err, result) {
|
(function next(err, result) {
|
||||||
if (i++ === n)
|
if (i++ === n)
|
||||||
|
@ -40,14 +42,16 @@ function main({ n, method, inputLen }) {
|
||||||
deflate(chunk, next);
|
deflate(chunk, next);
|
||||||
})();
|
})();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
// Performs `n` single deflateSync operations
|
// Performs `n` single deflateSync operations
|
||||||
case 'deflateSync':
|
case 'deflateSync': {
|
||||||
var deflateSync = zlib.deflateSync;
|
const deflateSync = zlib.deflateSync;
|
||||||
bench.start();
|
bench.start();
|
||||||
for (; i < n; ++i)
|
for (let i = 0; i < n; ++i)
|
||||||
deflateSync(chunk);
|
deflateSync(chunk);
|
||||||
bench.end(n);
|
bench.end(n);
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
throw new Error('Unsupported deflate method');
|
throw new Error('Unsupported deflate method');
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue