File tree Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Expand file tree Collapse file tree 2 files changed +49
-0
lines changed Original file line number Diff line number Diff line change 1+ 'use strict' ;
2+ const common = require ( '../common.js' ) ;
3+ const URLSearchParams = require ( 'url' ) . URLSearchParams ;
4+
5+ const inputs = {
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+ function getParams ( str ) {
20+ const out = [ ] ;
21+ for ( const key of str . split ( '&' ) ) {
22+ out . push ( key , '' ) ;
23+ }
24+ return out ;
25+ }
26+
27+ const bench = common . createBenchmark ( main , {
28+ type : Object . keys ( inputs ) ,
29+ n : [ 1e6 ]
30+ } , {
31+ flags : [ '--expose-internals' ]
32+ } ) ;
33+
34+ function main ( conf ) {
35+ const searchParams = require ( 'internal/url' ) . searchParamsSymbol ;
36+ const input = inputs [ conf . type ] ;
37+ const n = conf . n | 0 ;
38+ const params = new URLSearchParams ( ) ;
39+ const array = getParams ( input ) ;
40+
41+ var i ;
42+ bench . start ( ) ;
43+ for ( i = 0 ; i < n ; i ++ ) {
44+ params [ searchParams ] = array . slice ( ) ;
45+ params . sort ( ) ;
46+ }
47+ bench . end ( n ) ;
48+ }
Original file line number Diff line number Diff line change @@ -1257,3 +1257,4 @@ exports.domainToUnicode = domainToUnicode;
12571257exports . encodeAuth = encodeAuth ;
12581258exports . urlToOptions = urlToOptions ;
12591259exports . formatSymbol = kFormat ;
1260+ exports . searchParamsSymbol = searchParams ;
You can’t perform that action at this time.
0 commit comments