forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PR-URL: nodejs#11464 Reviewed-By: Steven R Loomis <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
- Loading branch information
1 parent
39b0034
commit 842ac58
Showing
1 changed file
with
47 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |