From 842ac583f6df969d40f7f875471c9851f1f14930 Mon Sep 17 00:00:00 2001 From: Timothy Gu Date: Sun, 19 Feb 2017 16:51:40 -0800 Subject: benchmark: add url.domainTo*() PR-URL: https://github.com/nodejs/node/pull/11464 Reviewed-By: Steven R Loomis Reviewed-By: Anna Henningsen Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell --- benchmark/url/whatwg-url-idna.js | 47 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 benchmark/url/whatwg-url-idna.js (limited to 'benchmark') diff --git a/benchmark/url/whatwg-url-idna.js b/benchmark/url/whatwg-url-idna.js new file mode 100644 index 00000000000..41b4c639de9 --- /dev/null +++ b/benchmark/url/whatwg-url-idna.js @@ -0,0 +1,47 @@ +'use strict'; +const common = require('../common.js'); +const { domainToASCII, domainToUnicode } = require('url'); + +const inputs = { + 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, { + input: Object.keys(inputs), + to: ['ascii', 'unicode'], + n: [5e6] +}); + +function main(conf) { + const n = conf.n | 0; + const to = conf.to; + const input = inputs[conf.input][to]; + const method = to === 'ascii' ? domainToASCII : domainToUnicode; + + common.v8ForceOptimization(method, input); + + bench.start(); + for (var i = 0; i < n; i++) { + method(input); + } + bench.end(n); +} -- cgit v1.2.3