node/benchmark/zlib/inflate.js
Rich Trott 362f5edf8c
tools,benchmark,lib,test: enable no-case-declarations lint rule
PR-URL: https://github.com/nodejs/node/pull/41385
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Tobias Nießen <tniessen@tnie.de>
Reviewed-By: Tierney Cyren <hello@bnb.im>
Reviewed-By: Ricky Zhou <0x19951125@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2022-01-31 23:54:42 -05:00

41 lines
992 B
JavaScript

'use strict';
const common = require('../common.js');
const zlib = require('zlib');
const bench = common.createBenchmark(main, {
method: ['inflate', 'inflateSync'],
inputLen: [1024],
n: [4e5]
});
function main({ n, method, inputLen }) {
// Default method value for tests.
method = method || 'inflate';
const chunk = zlib.deflateSync(Buffer.alloc(inputLen, 'a'));
let i = 0;
switch (method) {
// Performs `n` single inflate operations
case 'inflate': {
const inflate = zlib.inflate;
bench.start();
(function next(err, result) {
if (i++ === n)
return bench.end(n);
inflate(chunk, next);
})();
break;
}
// Performs `n` single inflateSync operations
case 'inflateSync': {
const inflateSync = zlib.inflateSync;
bench.start();
for (; i < n; ++i)
inflateSync(chunk);
bench.end(n);
break;
}
default:
throw new Error('Unsupported inflate method');
}
}