0
0
mirror of https://github.com/nodejs/node.git synced 2024-12-01 16:10:02 +01:00
nodejs/benchmark/zlib/creation.js
Ruben Bridgewater 5dfb93d2fa
benchmark: (zlib) use destructuring
PR-URL: https://github.com/nodejs/node/pull/18250
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2018-01-23 01:29:16 +01:00

32 lines
647 B
JavaScript

'use strict';
const common = require('../common.js');
const zlib = require('zlib');
const bench = common.createBenchmark(main, {
type: [
'Deflate', 'DeflateRaw', 'Inflate', 'InflateRaw', 'Gzip', 'Gunzip', 'Unzip'
],
options: ['true', 'false'],
n: [5e5]
});
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)
fn(opts);
bench.end(n);
} else {
bench.start();
for (; i < n; ++i)
fn();
bench.end(n);
}
}