Skip to content

benchmark: update benchmark for URLSearchParams.sort #50568

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 7 additions & 10 deletions benchmark/url/url-searchparams-sort.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,27 @@ const inputs = {
};

function getParams(str) {
const out = [];
for (const key of str.split('&')) {
out.push(key, '');
}
return out;
return str.split('&');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the original getParams is correct on returning a params initialization array. After the change, it is partial and needs more work at line 33.

}

const bench = common.createBenchmark(main, {
type: Object.keys(inputs),
n: [1e6],
}, {
flags: ['--expose-internals'],
});

function main({ type, n }) {
const searchParams = require('internal/url').searchParamsSymbol;
const input = inputs[type];
const params = new URLSearchParams();
const array = getParams(input);

for (let i = 0; i < array.length; i++) {
params.append(array[i], '');
}

bench.start();
for (let i = 0; i < n; i++) {
params[searchParams] = array.slice();
params.sort();
const paramsForSort = new URLSearchParams(params);
paramsForSort.sort();
}
bench.end(n);
}