1'use strict'; 2const common = require('../common.js'); 3 4const inputs = { 5 wpt: 'wpt', // To work around tests 6 empty: '', 7 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', 8 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', 9 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', 10 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', 11 // 8 parameters 12 short: 'm&t&d&c&z&v&a&n', 13 // 88 parameters 14 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&' + 15 '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&' + 16 'k&f&j&i&l&m&g&j&d&i&z&q&p&x&q&q&d&n&y&w&g&i&v&r' 17}; 18 19function getParams(str) { 20 const out = []; 21 for (const key of str.split('&')) { 22 out.push(key, ''); 23 } 24 return out; 25} 26 27const bench = common.createBenchmark(main, { 28 type: Object.keys(inputs), 29 n: [1e6] 30}, { 31 flags: ['--expose-internals'] 32}); 33 34function main({ type, n }) { 35 const searchParams = require('internal/url').searchParamsSymbol; 36 const input = inputs[type]; 37 const params = new URLSearchParams(); 38 const array = getParams(input); 39 40 bench.start(); 41 for (let i = 0; i < n; i++) { 42 params[searchParams] = array.slice(); 43 params.sort(); 44 } 45 bench.end(n); 46} 47