process.stdin.resume();
process.stdin.setEncoding('utf8');
var iters = 1000000,
counter = 1,
string = "abc0123$%^&*фываЁ",
etalon = withRegex( string );
function withRegex( string ) {
return string.replace( /[^a-z0-9а-яё]/ig, '' );
};
function withRegex2( string ) {
return string.replace( /[^a-z0-9а-яё]+/ig, '' );
};
function withPureJS( string ) {
var result = '',
length = string.length;
for ( var pos = 0; pos < string.length; pos++ ) {
result += parseChar(string.charCodeAt(pos))
};
return result;
};
function parseChar(c) {
if(( c > 47 && c < 58 ) || ( c > 64 && c < 91 ) || ( c > 96 && c < 123 ) ||
( c > 1071 && c < 1104 ) || ( c > 1039 && c < 1072 ) || c == 1105 || c == 1025) {
return String.fromCharCode(c);
}
return '';
}
function test( func, string, iters, etalon ) {
var tStart = Date.now();
for ( var i=0; i<iters; i++ ) {
if ( func( string ) !== etalon ) {
console.log( "error" );
break;
};
};
var tEnd = Date.now();
console.log( "test " + counter++, tEnd - tStart );
};
console.log( "Test started" );
test( withRegex, string, iters, etalon );
test( withRegex2, string, iters, etalon );
test( withPureJS, string, iters, etalon );
cHJvY2Vzcy5zdGRpbi5yZXN1bWUoKTsKcHJvY2Vzcy5zdGRpbi5zZXRFbmNvZGluZygndXRmOCcpOwoKdmFyIGl0ZXJzID0gMTAwMDAwMCwKICAgIGNvdW50ZXIgPSAxLAogICAgc3RyaW5nID0gImFiYzAxMjMkJV4mKtGE0YvQstCw0IEiLAogICAgZXRhbG9uID0gd2l0aFJlZ2V4KCBzdHJpbmcgKTsKCmZ1bmN0aW9uIHdpdGhSZWdleCggc3RyaW5nICkgewogIHJldHVybiBzdHJpbmcucmVwbGFjZSggL1teYS16MC050LAt0Y/RkV0vaWcsICcnICk7Cn07CgpmdW5jdGlvbiB3aXRoUmVnZXgyKCBzdHJpbmcgKSB7CiAgcmV0dXJuIHN0cmluZy5yZXBsYWNlKCAvW15hLXowLTnQsC3Rj9GRXSsvaWcsICcnICk7Cn07CgpmdW5jdGlvbiB3aXRoUHVyZUpTKCBzdHJp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