• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common.js');
3const zlib = require('zlib');
4
5const bench = common.createBenchmark(main, {
6  type: [
7    'Deflate', 'DeflateRaw', 'Inflate', 'InflateRaw', 'Gzip', 'Gunzip', 'Unzip',
8    'BrotliCompress', 'BrotliDecompress',
9  ],
10  options: ['true', 'false'],
11  n: [5e5]
12});
13
14function main({ n, type, options }) {
15  const fn = zlib[`create${type}`];
16  if (typeof fn !== 'function')
17    throw new Error('Invalid zlib type');
18
19  if (options === 'true') {
20    const opts = {};
21    bench.start();
22    for (let i = 0; i < n; ++i)
23      fn(opts);
24    bench.end(n);
25  } else {
26    bench.start();
27    for (let i = 0; i < n; ++i)
28      fn();
29    bench.end(n);
30  }
31}
32