File tree 1 file changed +47
-0
lines changed
1 file changed +47
-0
lines changed Original file line number Diff line number Diff line change
1
+ 'use strict' ;
2
+ const common = require ( '../common.js' ) ;
3
+ const { domainToASCII, domainToUnicode } = require ( 'url' ) ;
4
+
5
+ const inputs = {
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
+ const bench = common . createBenchmark ( main , {
29
+ input : Object . keys ( inputs ) ,
30
+ to : [ 'ascii' , 'unicode' ] ,
31
+ n : [ 5e6 ]
32
+ } ) ;
33
+
34
+ function main ( conf ) {
35
+ const n = conf . n | 0 ;
36
+ const to = conf . to ;
37
+ const input = inputs [ conf . input ] [ to ] ;
38
+ const method = to === 'ascii' ? domainToASCII : domainToUnicode ;
39
+
40
+ common . v8ForceOptimization ( method , input ) ;
41
+
42
+ bench . start ( ) ;
43
+ for ( var i = 0 ; i < n ; i ++ ) {
44
+ method ( input ) ;
45
+ }
46
+ bench . end ( n ) ;
47
+ }
You can’t perform that action at this time.
0 commit comments