• 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  inputLen: [16 * 1024 * 1024],
7  chunkLen: [1024],
8  n: [1e2]
9});
10
11function main({ n, inputLen, chunkLen }) {
12  const input = zlib.deflateSync(Buffer.alloc(inputLen, 'a'));
13
14  let i = 0;
15  bench.start();
16  (function next() {
17    let p = 0;
18    const inflater = zlib.createInflate();
19    inflater.resume();
20    inflater.on('finish', () => {
21      if (i++ === n)
22        return bench.end(n);
23      next();
24    });
25
26    (function nextChunk() {
27      if (p >= input.length)
28        return inflater.end();
29      inflater.write(input.slice(p, p += chunkLen), nextChunk);
30    })();
31  })();
32}
33