mirror of
https://github.com/nodejs/node.git
synced 2024-11-28 14:33:11 +01:00
3aef395ed5
PR-URL: https://github.com/nodejs/node/pull/46551 Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Akhil Marsonya <akhil.marsonya27@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
44 lines
866 B
JavaScript
44 lines
866 B
JavaScript
'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);
|
|
}
|