summaryrefslogtreecommitdiff
path: root/benchmark/zlib/creation.js
blob: f23759fa0ebf38db752d3542487f671dc24ac1d1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
'use strict';
const common = require('../common.js');
const zlib = require('zlib');

const bench = common.createBenchmark(main, {
  type: [
    'Deflate', 'DeflateRaw', 'Inflate', 'InflateRaw', 'Gzip', 'Gunzip', 'Unzip',
    'BrotliCompress', 'BrotliDecompress'
  ],
  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);
  }
}