2016-06-21 23:03:05 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common.js');
|
2017-10-17 07:31:52 +02:00
|
|
|
let icu;
|
|
|
|
try {
|
2018-10-12 18:45:26 +02:00
|
|
|
icu = common.binding('icu');
|
2018-11-04 18:38:54 +01:00
|
|
|
} catch {}
|
2016-06-21 23:03:05 +02:00
|
|
|
const punycode = require('punycode');
|
|
|
|
|
|
|
|
const bench = common.createBenchmark(main, {
|
2017-10-17 07:31:52 +02:00
|
|
|
method: ['punycode'].concat(icu !== undefined ? ['icu'] : []),
|
2016-06-21 23:03:05 +02:00
|
|
|
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) {
|
|
|
|
var i = 0;
|
2017-03-01 12:36:27 +01:00
|
|
|
for (; i < n; i++)
|
|
|
|
usingPunycode(val);
|
2016-06-21 23:03:05 +02:00
|
|
|
bench.start();
|
2017-03-09 22:01:45 +01:00
|
|
|
for (i = 0; i < n; i++)
|
2016-06-21 23:03:05 +02:00
|
|
|
usingPunycode(val);
|
|
|
|
bench.end(n);
|
|
|
|
}
|
|
|
|
|
|
|
|
function runICU(n, val) {
|
|
|
|
bench.start();
|
2018-01-23 13:19:30 +01:00
|
|
|
for (var i = 0; i < n; i++)
|
2016-06-21 23:03:05 +02:00
|
|
|
usingICU(val);
|
|
|
|
bench.end(n);
|
|
|
|
}
|
|
|
|
|
2017-12-30 03:57:38 +01:00
|
|
|
function main({ n, val, method }) {
|
|
|
|
switch (method) {
|
2017-10-10 08:56:21 +02:00
|
|
|
// '' is a default case for tests
|
|
|
|
case '':
|
2016-06-21 23:03:05 +02:00
|
|
|
case 'punycode':
|
|
|
|
runPunycode(n, val);
|
|
|
|
break;
|
|
|
|
case 'icu':
|
2017-10-17 07:31:52 +02:00
|
|
|
if (icu !== undefined) {
|
|
|
|
runICU(n, val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
// fallthrough
|
2016-06-21 23:03:05 +02:00
|
|
|
default:
|
2018-01-23 13:19:30 +01:00
|
|
|
throw new Error(`Unexpected method "${method}"`);
|
2016-06-21 23:03:05 +02:00
|
|
|
}
|
|
|
|
}
|