11'use strict' ;
2+ const common = require ( '../common.js' ) ;
3+ const URL = require ( 'url' ) . URL ;
4+ const inputs = require ( '../fixtures/url-inputs.js' ) . urls ;
25
3- var common = require ( '../common.js' ) ;
4- var URL = require ( 'url' ) . URL ;
5-
6- var bench = common . createBenchmark ( main , {
7- url : [
8- 'http://example.com/' ,
9- 'https://encrypted.google.com/search?q=url&q=site:npmjs.org&hl=en' ,
10- 'javascript:alert("node is awesome");' ,
11- 'http://user:pass@foo.bar.com:21/aaa/zzz?l=24#test'
12- ] ,
13- prop : [ 'toString' , 'href' , 'origin' , 'protocol' ,
6+ const bench = common . createBenchmark ( main , {
7+ input : Object . keys ( inputs ) ,
8+ prop : [ 'href' , 'origin' , 'protocol' ,
149 'username' , 'password' , 'host' , 'hostname' , 'port' ,
1510 'pathname' , 'search' , 'searchParams' , 'hash' ] ,
1611 n : [ 1e4 ]
@@ -34,14 +29,6 @@ function get(n, url, prop) {
3429 bench . end ( n ) ;
3530}
3631
37- function stringify ( n , url , prop ) {
38- bench . start ( ) ;
39- for ( var i = 0 ; i < n ; i += 1 ) {
40- url . toString ( ) ;
41- }
42- bench . end ( n ) ;
43- }
44-
4532const alternatives = {
4633 href : 'http://user:pass@foo.bar.com:21/aaa/zzz?l=25#test' ,
4734 protocol : 'https:' ,
@@ -61,7 +48,8 @@ function getAlternative(prop) {
6148
6249function main ( conf ) {
6350 const n = conf . n | 0 ;
64- const url = new URL ( conf . url ) ;
51+ const input = inputs [ conf . input ] ;
52+ const url = new URL ( input ) ;
6553 const prop = conf . prop ;
6654
6755 switch ( prop ) {
@@ -74,17 +62,13 @@ function main(conf) {
7462 case 'pathname' :
7563 case 'search' :
7664 case 'hash' :
65+ case 'href' :
7766 setAndGet ( n , url , prop , getAlternative ( prop ) ) ;
7867 break ;
79- // TODO: move href to the first group when the setter lands.
80- case 'href' :
8168 case 'origin' :
8269 case 'searchParams' :
8370 get ( n , url , prop ) ;
8471 break ;
85- case 'toString' :
86- stringify ( n , url ) ;
87- break ;
8872 default :
8973 throw new Error ( 'Unknown prop' ) ;
9074 }
0 commit comments