Skip to content

Commit 54dde7e

Browse files
committed
benchmark: add url/url-searchparams-sort.js
1 parent 798b358 commit 54dde7e

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use strict';
2+
constcommon=require('../common.js');
3+
constURLSearchParams=require('url').URLSearchParams;
4+
5+
constinputs={
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+
19+
functiongetParams(str){
20+
constout=[];
21+
for(constkeyofstr.split('&')){
22+
out.push(key,'');
23+
}
24+
returnout;
25+
}
26+
27+
constbench=common.createBenchmark(main,{
28+
type: Object.keys(inputs),
29+
n: [1e6]
30+
},{
31+
flags: ['--expose-internals']
32+
});
33+
34+
functionmain(conf){
35+
constsearchParams=require('internal/url').searchParamsSymbol;
36+
constinput=inputs[conf.type];
37+
constn=conf.n|0;
38+
constparams=newURLSearchParams();
39+
constarray=getParams(input);
40+
41+
vari;
42+
bench.start();
43+
for(i=0;i<n;i++){
44+
params[searchParams]=array.slice();
45+
params.sort();
46+
}
47+
bench.end(n);
48+
}

‎lib/internal/url.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1257,3 +1257,4 @@ exports.domainToUnicode = domainToUnicode;
12571257
exports.encodeAuth=encodeAuth;
12581258
exports.urlToOptions=urlToOptions;
12591259
exports.formatSymbol=kFormat;
1260+
exports.searchParamsSymbol=searchParams;

0 commit comments

Comments
(0)