1
1
'use strict' ;
2
+ const common = require ( '../common.js' ) ;
3
+ const URL = require ( 'url' ) . URL ;
4
+ const inputs = require ( '../fixtures/url-inputs.js' ) . urls ;
2
5
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:[email protected] :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' ,
14
9
'username' , 'password' , 'host' , 'hostname' , 'port' ,
15
10
'pathname' , 'search' , 'searchParams' , 'hash' ] ,
16
11
n : [ 1e4 ]
@@ -34,14 +29,6 @@ function get(n, url, prop) {
34
29
bench . end ( n ) ;
35
30
}
36
31
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
-
45
32
const alternatives = {
46
33
href :
'http://user:[email protected] :21/aaa/zzz?l=25#test' ,
47
34
protocol : 'https:' ,
@@ -61,7 +48,8 @@ function getAlternative(prop) {
61
48
62
49
function main ( conf ) {
63
50
const n = conf . n | 0 ;
64
- const url = new URL ( conf . url ) ;
51
+ const input = inputs [ conf . input ] ;
52
+ const url = new URL ( input ) ;
65
53
const prop = conf . prop ;
66
54
67
55
switch ( prop ) {
@@ -74,17 +62,13 @@ function main(conf) {
74
62
case 'pathname' :
75
63
case 'search' :
76
64
case 'hash' :
65
+ case 'href' :
77
66
setAndGet ( n , url , prop , getAlternative ( prop ) ) ;
78
67
break ;
79
- // TODO: move href to the first group when the setter lands.
80
- case 'href' :
81
68
case 'origin' :
82
69
case 'searchParams' :
83
70
get ( n , url , prop ) ;
84
71
break ;
85
- case 'toString' :
86
- stringify ( n , url ) ;
87
- break ;
88
72
default :
89
73
throw new Error ( 'Unknown prop' ) ;
90
74
}
0 commit comments