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 type: [ 71cb0ef41Sopenharmony_ci 'Deflate', 'DeflateRaw', 'Inflate', 'InflateRaw', 'Gzip', 'Gunzip', 'Unzip', 81cb0ef41Sopenharmony_ci 'BrotliCompress', 'BrotliDecompress', 91cb0ef41Sopenharmony_ci ], 101cb0ef41Sopenharmony_ci options: ['true', 'false'], 111cb0ef41Sopenharmony_ci n: [5e5], 121cb0ef41Sopenharmony_ci}); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_cifunction main({ n, type, options }) { 151cb0ef41Sopenharmony_ci const fn = zlib[`create${type}`]; 161cb0ef41Sopenharmony_ci if (typeof fn !== 'function') 171cb0ef41Sopenharmony_ci throw new Error('Invalid zlib type'); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci if (options === 'true') { 201cb0ef41Sopenharmony_ci const opts = {}; 211cb0ef41Sopenharmony_ci bench.start(); 221cb0ef41Sopenharmony_ci for (let i = 0; i < n; ++i) 231cb0ef41Sopenharmony_ci fn(opts); 241cb0ef41Sopenharmony_ci bench.end(n); 251cb0ef41Sopenharmony_ci } else { 261cb0ef41Sopenharmony_ci bench.start(); 271cb0ef41Sopenharmony_ci for (let i = 0; i < n; ++i) 281cb0ef41Sopenharmony_ci fn(); 291cb0ef41Sopenharmony_ci bench.end(n); 301cb0ef41Sopenharmony_ci } 311cb0ef41Sopenharmony_ci} 32