0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/benchmark/url/whatwg-url-idna.js
Antoine du Hamel 3aef395ed5
benchmark: add trailing commas in benchmark/url
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>
2023-02-10 00:54:40 +00:00

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);
}