1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
'use strict';
const common = require('../common.js');
const { domainToASCII, domainToUnicode } = require('url');
const domains = {
empty: {
ascii: '',
unicode: ''
},
none: {
ascii: 'passports',
unicode: 'passports'
},
some: {
ascii: 'Paßstraße',
unicode: 'xn--Pastrae-1vae'
},
all: {
ascii: '他们不说中文',
unicode: 'xn--ihqwczyycu19kkg2c'
},
nonstring: {
ascii: { toString() { return ''; } },
unicode: { toString() { return ''; } }
}
};
const bench = common.createBenchmark(main, {
domain: Object.keys(domains),
to: ['ascii', 'unicode'],
n: [5e6]
});
function main({ n, to, domain }) {
const value = domains[domain][to];
const method = to === 'ascii' ? domainToASCII : domainToUnicode;
bench.start();
for (let i = 0; i < n; i++) {
method(value);
}
bench.end(n);
}
|