Skip to content

Commit

Permalink
benchmark: add url.domainTo*()
Browse files Browse the repository at this point in the history
  • Loading branch information
TimothyGu committed Feb 23, 2017
1 parent 199d115 commit b5acb67
Showing 1 changed file with 47 additions and 0 deletions.
47 changes: 47 additions & 0 deletions benchmark/url/whatwg-url-idna.js
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit b5acb67

Please sign in to comment.