@@ -3,30 +3,43 @@ var common = require('../common.js');
33var url = require ( 'url' ) ;
44var v8 = require ( 'v8' ) ;
55
6+ var hrefs = [
7+ 'http://example.com/' ,
8+ 'http://nodejs.org/docs/latest/api/url.html#url_url_format_urlobj' ,
9+ 'http://blog.nodejs.org/' ,
10+ 'https://encrypted.google.com/search?q=url&q=site:npmjs.org&hl=en' ,
11+ 'javascript:alert("node is awesome");' ,
12+ 'some.ran/dom/url.thing?oh=yes#whoo'
13+ ] ;
14+
15+
16+ var paths = [
17+ '../../../../../etc/passwd' ,
18+ '../foo/bar?baz=boom' ,
19+ 'foo/bar' ,
20+ 'http://nodejs.org' ,
21+ './foo/bar?baz'
22+ ] ;
23+
624var bench = common . createBenchmark ( main , {
7- type : [ 'one' ] ,
8- n : [ 1e5 ] ,
25+ href : Object . keys ( hrefs ) ,
26+ path : Object . keys ( paths ) ,
27+ n : [ 1e5 ]
928} ) ;
1029
1130function main ( conf ) {
12- var type = conf . type ;
1331 var n = conf . n | 0 ;
14-
15- var inputs = {
16- one : [ 'http://example.com/' , '../../../../../etc/passwd' ] ,
17- } ;
18- var input = inputs [ type ] || [ ] ;
32+ var href = hrefs [ conf . href ] ;
33+ var path = paths [ conf . path ] ;
1934
2035 // Force-optimize url.resolve() so that the benchmark doesn't get
2136 // disrupted by the optimizer kicking in halfway through.
22- for ( var name in inputs )
23- url . resolve ( inputs [ name ] [ 0 ] , inputs [ name ] [ 1 ] ) ;
24-
37+ url . resolve ( href , path ) ;
2538 v8 . setFlagsFromString ( '--allow_natives_syntax' ) ;
2639 eval ( '%OptimizeFunctionOnNextCall(url.resolve)' ) ;
2740
2841 bench . start ( ) ;
2942 for ( var i = 0 ; i < n ; i += 1 )
30- url . resolve ( input [ 0 ] , input [ 1 ] ) ;
43+ url . resolve ( href , path ) ;
3144 bench . end ( n ) ;
3245}
0 commit comments