11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common.js'); 31cb0ef41Sopenharmony_ciconst zlib = require('zlib'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 61cb0ef41Sopenharmony_ci inputLen: [16 * 1024 * 1024], 71cb0ef41Sopenharmony_ci chunkLen: [1024], 81cb0ef41Sopenharmony_ci n: [1e2], 91cb0ef41Sopenharmony_ci}); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_cifunction main({ n, inputLen, chunkLen }) { 121cb0ef41Sopenharmony_ci const input = zlib.deflateSync(Buffer.alloc(inputLen, 'a')); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci let i = 0; 151cb0ef41Sopenharmony_ci bench.start(); 161cb0ef41Sopenharmony_ci (function next() { 171cb0ef41Sopenharmony_ci let p = 0; 181cb0ef41Sopenharmony_ci const inflater = zlib.createInflate(); 191cb0ef41Sopenharmony_ci inflater.resume(); 201cb0ef41Sopenharmony_ci inflater.on('finish', () => { 211cb0ef41Sopenharmony_ci if (i++ === n) 221cb0ef41Sopenharmony_ci return bench.end(n); 231cb0ef41Sopenharmony_ci next(); 241cb0ef41Sopenharmony_ci }); 251cb0ef41Sopenharmony_ci 261cb0ef41Sopenharmony_ci (function nextChunk() { 271cb0ef41Sopenharmony_ci if (p >= input.length) 281cb0ef41Sopenharmony_ci return inflater.end(); 291cb0ef41Sopenharmony_ci inflater.write(input.slice(p, p += chunkLen), nextChunk); 301cb0ef41Sopenharmony_ci })(); 311cb0ef41Sopenharmony_ci })(); 321cb0ef41Sopenharmony_ci} 33