Skip to content

Commit 4ce8412

Browse files
RafaelGSSrichardlau
authored andcommitted
benchmark: fix url-searchparams-sort to sort a fresh list
Copying from another URLSearchParams only slices its internal list, so every iteration sorts a fresh, unsorted copy. Refs: #50566 Signed-off-by: RafaelGSS <[email protected]> PR-URL: #66535 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Ulises Gascón <[email protected]>
1 parent 8462363 commit 4ce8412

1 file changed

Lines changed: 2 additions & 15 deletions

File tree

‎benchmark/url/url-searchparams-sort.js‎

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,17 @@ const inputs = {
1616
'k&f&j&i&l&m&g&j&d&i&z&q&p&x&q&q&d&n&y&w&g&i&v&r',
1717
};
1818

19-
function getParams(str) {
20-
const out = [];
21-
for (const key of str.split('&')) {
22-
out.push(key, '');
23-
}
24-
return out;
25-
}
26-
2719
const bench = common.createBenchmark(main, {
2820
type: Object.keys(inputs),
2921
n: [1e6],
30-
}, {
31-
flags: ['--expose-internals'],
3222
});
3323

3424
function 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);
25+
const base = new URLSearchParams(inputs[type]);
3926

4027
bench.start();
4128
for (let i = 0; i < n; i++) {
42-
params[searchParams] = array.slice();
29+
const params = new URLSearchParams(base);
4330
params.sort();
4431
}
4532
bench.end(n);

0 commit comments

Comments
 (0)