diff options
author | Brian White <mscdex@mscdex.net> | 2016-12-24 23:27:46 -0500 |
---|---|---|
committer | Brian White <mscdex@mscdex.net> | 2017-01-05 02:41:22 -0500 |
commit | d43b14495c894d8836897056dbb6df2a7df11467 (patch) | |
tree | aaf3c3e8955ab9d8897f460b22130d2f2a7d4659 /benchmark/misc/punycode.js | |
parent | 26f2a6e87ce3911f5546ab24ee6a6d7c36587524 (diff) | |
download | android-node-v8-d43b14495c894d8836897056dbb6df2a7df11467.tar.gz android-node-v8-d43b14495c894d8836897056dbb6df2a7df11467.tar.bz2 android-node-v8-d43b14495c894d8836897056dbb6df2a7df11467.zip |
benchmark: move punycode benchmark out of net
punycode/ICU is not specific to any particular module, so move it to
a more generic location.
PR-URL: https://github.com/nodejs/node/pull/10446
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'benchmark/misc/punycode.js')
-rw-r--r-- | benchmark/misc/punycode.js | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/benchmark/misc/punycode.js b/benchmark/misc/punycode.js new file mode 100644 index 0000000000..f4d22557ac --- /dev/null +++ b/benchmark/misc/punycode.js @@ -0,0 +1,75 @@ +'use strict'; + +const common = require('../common.js'); +const icu = process.binding('icu'); +const punycode = require('punycode'); + +const bench = common.createBenchmark(main, { + method: ['punycode', 'icu'], + n: [1024], + val: [ + 'افغانستا.icom.museum', + 'الجزائر.icom.museum', + 'österreich.icom.museum', + 'বাংলাদেশ.icom.museum', + 'беларусь.icom.museum', + 'belgië.icom.museum', + 'българия.icom.museum', + 'تشادر.icom.museum', + '中国.icom.museum', + 'القمر.icom.museum', + 'κυπρος.icom.museum', + 'českárepublika.icom.museum', + 'مصر.icom.museum', + 'ελλάδα.icom.museum', + 'magyarország.icom.museum', + 'ísland.icom.museum', + 'भारत.icom.museum', + 'ايران.icom.museum', + 'éire.icom.museum', + 'איקו״ם.ישראל.museum', + '日本.icom.museum', + 'الأردن.icom.museum' + ] +}); + +function usingPunycode(val) { + punycode.toUnicode(punycode.toASCII(val)); +} + +function usingICU(val) { + icu.toUnicode(icu.toASCII(val)); +} + +function runPunycode(n, val) { + common.v8ForceOptimization(usingPunycode, val); + var i = 0; + bench.start(); + for (; i < n; i++) + usingPunycode(val); + bench.end(n); +} + +function runICU(n, val) { + common.v8ForceOptimization(usingICU, val); + var i = 0; + bench.start(); + for (; i < n; i++) + usingICU(val); + bench.end(n); +} + +function main(conf) { + const n = +conf.n; + const val = conf.val; + switch (conf.method) { + case 'punycode': + runPunycode(n, val); + break; + case 'icu': + runICU(n, val); + break; + default: + throw new Error('Unexpected method'); + } +} |