Skip to content

Commit 842ac58

Browse files
TimothyGuItalo A. Casas
authored andcommitted
benchmark: add url.domainTo*()
PR-URL: #11464 Reviewed-By: Steven R Loomis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 39b0034 commit 842ac58

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

‎benchmark/url/whatwg-url-idna.js‎

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
'use strict';
2+
constcommon=require('../common.js');
3+
const{ domainToASCII, domainToUnicode }=require('url');
4+
5+
constinputs={
6+
empty: {
7+
ascii: '',
8+
unicode: ''
9+
},
10+
none: {
11+
ascii: 'passports',
12+
unicode: 'passports'
13+
},
14+
some: {
15+
ascii: 'Paßstraße',
16+
unicode: 'xn--Pastrae-1vae'
17+
},
18+
all: {
19+
ascii: '他们不说中文',
20+
unicode: 'xn--ihqwczyycu19kkg2c'
21+
},
22+
nonstring: {
23+
ascii: {toString(){return'';}},
24+
unicode: {toString(){return'';}}
25+
}
26+
};
27+
28+
constbench=common.createBenchmark(main,{
29+
input: Object.keys(inputs),
30+
to: ['ascii','unicode'],
31+
n: [5e6]
32+
});
33+
34+
functionmain(conf){
35+
constn=conf.n|0;
36+
constto=conf.to;
37+
constinput=inputs[conf.input][to];
38+
constmethod=to==='ascii' ? domainToASCII : domainToUnicode;
39+
40+
common.v8ForceOptimization(method,input);
41+
42+
bench.start();
43+
for(vari=0;i<n;i++){
44+
method(input);
45+
}
46+
bench.end(n);
47+
}

0 commit comments

Comments
(0)