summaryrefslogtreecommitdiff
path: root/benchmark/zlib/creation.js
blob: 4984bf1a86b755eaeecc499466c2cd5673e4a9fa (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
'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);
  }
}