11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ciconst common = require('../common.js'); 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciconst inputs = { 51cb0ef41Sopenharmony_ci wpt: 'wpt', // To work around tests 61cb0ef41Sopenharmony_ci empty: '', 71cb0ef41Sopenharmony_ci sorted: 'a&b&c&d&e&f&g&h&i&j&k&l&m&n&o&p&q&r&s&t&u&v&w&x&y&z', 81cb0ef41Sopenharmony_ci almostsorted: 'a&b&c&d&e&f&g&i&h&j&k&l&m&n&o&p&q&r&s&t&u&w&v&x&y&z', 91cb0ef41Sopenharmony_ci reversed: 'z&y&x&w&v&u&t&s&r&q&p&o&n&m&l&k&j&i&h&g&f&e&d&c&b&a', 101cb0ef41Sopenharmony_ci random: 'm&t&d&c&z&v&a&n&p&y&u&o&h&l&f&j&e&q&b&i&s&x&k&w&r&g', 111cb0ef41Sopenharmony_ci // 8 parameters 121cb0ef41Sopenharmony_ci short: 'm&t&d&c&z&v&a&n', 131cb0ef41Sopenharmony_ci // 88 parameters 141cb0ef41Sopenharmony_ci long: 'g&r&t&h&s&r&d&w&b&n&h&k&x&m&k&h&o&e&x&c&c&g&e&b&p&p&s&n&j&b&y&z&' + 151cb0ef41Sopenharmony_ci 'u&l&o&r&w&a&u&l&m&f&j&q&p&f&e&y&e&n&e&l&m&w&u&w&t&n&t&q&v&y&c&o&' + 161cb0ef41Sopenharmony_ci 'k&f&j&i&l&m&g&j&d&i&z&q&p&x&q&q&d&n&y&w&g&i&v&r', 171cb0ef41Sopenharmony_ci}; 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_cifunction getParams(str) { 201cb0ef41Sopenharmony_ci const out = []; 211cb0ef41Sopenharmony_ci for (const key of str.split('&')) { 221cb0ef41Sopenharmony_ci out.push(key, ''); 231cb0ef41Sopenharmony_ci } 241cb0ef41Sopenharmony_ci return out; 251cb0ef41Sopenharmony_ci} 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 281cb0ef41Sopenharmony_ci type: Object.keys(inputs), 291cb0ef41Sopenharmony_ci n: [1e6], 301cb0ef41Sopenharmony_ci}, { 311cb0ef41Sopenharmony_ci flags: ['--expose-internals'], 321cb0ef41Sopenharmony_ci}); 331cb0ef41Sopenharmony_ci 341cb0ef41Sopenharmony_cifunction main({ type, n }) { 351cb0ef41Sopenharmony_ci const searchParams = require('internal/url').searchParamsSymbol; 361cb0ef41Sopenharmony_ci const input = inputs[type]; 371cb0ef41Sopenharmony_ci const params = new URLSearchParams(); 381cb0ef41Sopenharmony_ci const array = getParams(input); 391cb0ef41Sopenharmony_ci 401cb0ef41Sopenharmony_ci bench.start(); 411cb0ef41Sopenharmony_ci for (let i = 0; i < n; i++) { 421cb0ef41Sopenharmony_ci params[searchParams] = array.slice(); 431cb0ef41Sopenharmony_ci params.sort(); 441cb0ef41Sopenharmony_ci } 451cb0ef41Sopenharmony_ci bench.end(n); 461cb0ef41Sopenharmony_ci} 47