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 method: ['inflate', 'inflateSync'], 71cb0ef41Sopenharmony_ci inputLen: [1024], 81cb0ef41Sopenharmony_ci n: [4e5], 91cb0ef41Sopenharmony_ci}); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_cifunction main({ n, method, inputLen }) { 121cb0ef41Sopenharmony_ci // Default method value for tests. 131cb0ef41Sopenharmony_ci method = method || 'inflate'; 141cb0ef41Sopenharmony_ci const chunk = zlib.deflateSync(Buffer.alloc(inputLen, 'a')); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci let i = 0; 171cb0ef41Sopenharmony_ci switch (method) { 181cb0ef41Sopenharmony_ci // Performs `n` single inflate operations 191cb0ef41Sopenharmony_ci case 'inflate': { 201cb0ef41Sopenharmony_ci const inflate = zlib.inflate; 211cb0ef41Sopenharmony_ci bench.start(); 221cb0ef41Sopenharmony_ci (function next(err, result) { 231cb0ef41Sopenharmony_ci if (i++ === n) 241cb0ef41Sopenharmony_ci return bench.end(n); 251cb0ef41Sopenharmony_ci inflate(chunk, next); 261cb0ef41Sopenharmony_ci })(); 271cb0ef41Sopenharmony_ci break; 281cb0ef41Sopenharmony_ci } 291cb0ef41Sopenharmony_ci // Performs `n` single inflateSync operations 301cb0ef41Sopenharmony_ci case 'inflateSync': { 311cb0ef41Sopenharmony_ci const inflateSync = zlib.inflateSync; 321cb0ef41Sopenharmony_ci bench.start(); 331cb0ef41Sopenharmony_ci for (; i < n; ++i) 341cb0ef41Sopenharmony_ci inflateSync(chunk); 351cb0ef41Sopenharmony_ci bench.end(n); 361cb0ef41Sopenharmony_ci break; 371cb0ef41Sopenharmony_ci } 381cb0ef41Sopenharmony_ci default: 391cb0ef41Sopenharmony_ci throw new Error('Unsupported inflate method'); 401cb0ef41Sopenharmony_ci } 411cb0ef41Sopenharmony_ci} 42