@ 2017-12-09T10:42:41Z <?php
function ordutf8_step1(string $char) : int
{
$code = ord(substr($char, 0, 1));
if ($code >= 128) {
if ($code < 224)
$bytesnumber = 2;
else if ($code < 240)
$bytesnumber = 3;
else if ($code < 248)
$bytesnumber = 4;
$codetemp = $code - 192 - ($bytesnumber > 2 ? 32 : 0) - ($bytesnumber > 3 ? 16 : 0);
$offset = 0;
for ($i = 2; $i <= $bytesnumber; $i++) {
$offset ++;
$code2 = ord(substr($char, $offset, 1)) - 128;
$codetemp = $codetemp * 64 + $code2;
}
$code = $codetemp;
}
return $code;
}
function ordutf8_step2(string $char) : int
{
$code = ord(substr($char, 0, 1));
if ($code >= 128) {
$count = 0;
if ($code < 224) {
$bytesnumber = 2;
} else if ($code < 240) {
$bytesnumber = 3;
$count = 32;
} else if ($code < 248) {
$bytesnumber = 4;
$count = 48;
}
$codetemp = $code - 192 - $count;
$offset = 0;
for ($i = 2; $i <= $bytesnumber; $i++) {
$offset ++;
$code2 = ord(substr($char, $offset, 1)) - 128;
$codetemp = $codetemp * 64 + $code2;
}
$code = $codetemp;
}
return $code;
}
function ordutf8_step3(string $char) : int
{
$code = ord(substr($char, 0, 1));
if ($code >= 128) {
$count = 0;
if ($code < 224) {
$bytes = 2;
} else if ($code < 240) {
$bytes = 3;
$count = 32;
} else if ($code < 248) {
$bytes = 4;
$count = 48;
}
$temp = $code - 192 - $count;
for ($i = 1; $i < $bytes; $i++) {
$code = $temp = $temp * 64 + ord(substr($char, $i, 1)) - 128;
}
}
return $code;
}
function ordutf8_step4(string $char) : int
{
$code = ord(substr($char, 0, 1));
if ($code > 127) {
$bytes = 2;
$count = 0;
if ($code > 223){
$bytes = 3;
$count = 32;
}
if ($code > 239){
$bytes = 4;
$count = 48;
}
$temp = $code - 192 - $count;
for ($i = 1; $i < $bytes; $i++) {
$code = $temp = $temp * 64 + ord(substr($char, $i, 1)) - 128;
}
}
return $code;
}
function ordutf8_step5(string $char) : int
{
$code = ord(substr($char, 0, 1));
if ($code > 239){
return ((($code - 240) * 64 + ord(substr($char, 1, 1)) - 128) *
64 + ord(substr($char, 2, 1)) - 128) *
64 + ord(substr($char, 3, 1)) - 128;
}
if ($code > 223){
return (($code - 224) * 64 + ord(substr($char, 1, 1)) - 128)
* 64 + ord(substr($char, 2, 1)) - 128;
}
if ($code > 127) {
return ($code - 192) * 64 + ord(substr($char, 1, 1)) - 128;
}
return $code;
}
$cicles = 100000;
$char = 'ݟ';
$time = -microtime(true);
for($i = 0; $i < $cicles; $i++) {
ordutf8_step1($char);
}
$time += microtime(true);
echo $time;
echo "\n";
$time = -microtime(true);
for($i = 0; $i < $cicles; $i++) {
ordutf8_step2($char);
}
$time += microtime(true);
echo $time;
echo "\n";
$time = -microtime(true);
for($i = 0; $i < $cicles; $i++) {
ordutf8_step3($char);
}
$time += microtime(true);
echo $time;
echo "\n";
$time = -microtime(true);
for($i = 0; $i < $cicles; $i++) {
ordutf8_step4($char);
}
$time += microtime(true);
echo $time;
echo "\n";
$time = -microtime(true);
for($i = 0; $i < $cicles; $i++) {
ordutf8_step5($char);
}
$time += microtime(true);
echo $time;
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 7.4.0 0.007 0.222 15.00 7.3.12 0.007 0.176 14.85 7.3.11 0.003 0.223 14.86 7.3.10 0.007 0.200 14.80 7.3.9 0.007 0.214 14.86 7.3.8 0.007 0.189 14.81 7.3.7 0.010 0.171 14.84 7.3.6 0.003 0.193 15.05 7.3.5 0.000 0.170 14.65 7.3.4 0.010 0.167 14.64 7.3.3 0.007 0.195 14.95 7.3.2 0.000 0.171 16.77 7.3.1 0.007 0.166 16.33 7.3.0 0.007 0.166 16.33 7.2.25 0.000 0.291 15.39 7.2.24 0.010 0.280 15.19 7.2.23 0.003 0.193 15.14 7.2.22 0.003 0.215 15.00 7.2.21 0.003 0.200 14.84 7.2.20 0.013 0.178 15.21 7.2.19 0.003 0.178 15.09 7.2.18 0.000 0.231 15.07 7.2.17 0.007 0.212 15.23 7.2.16 0.007 0.190 15.31 7.2.15 0.010 0.179 17.02 7.2.14 0.000 0.211 17.05 7.2.13 0.000 0.180 17.00 7.2.12 0.003 0.194 17.00 7.2.11 0.000 0.198 16.84 7.2.10 0.007 0.199 16.92 7.2.9 0.003 0.186 17.09 7.2.8 0.003 0.180 16.97 7.2.7 0.007 0.173 16.68 7.2.6 0.007 0.161 16.93 7.2.5 0.010 0.183 17.13 7.2.4 0.000 0.170 17.10 7.2.3 0.000 0.180 16.85 7.2.2 0.007 0.173 17.04 7.2.1 0.010 0.182 17.02 7.2.0 0.005 0.136 18.31 7.1.33 0.003 0.330 15.89 7.1.32 0.003 0.340 15.87 7.1.31 0.000 0.302 15.87 7.1.30 0.003 0.352 15.96 7.1.29 0.007 0.310 15.81 7.1.28 0.007 0.346 15.74 7.1.27 0.003 0.309 15.76 7.1.26 0.000 0.291 15.80 7.1.25 0.007 0.310 16.03 7.1.12 0.003 0.128 18.70 7.1.11 0.007 0.126 18.15 7.1.10 0.007 0.126 18.33 7.1.9 0.007 0.129 18.12 7.1.8 0.007 0.123 17.96 7.1.7 0.004 0.133 17.20 7.1.6 0.017 0.126 35.26 7.1.5 0.014 0.129 35.01 7.1.4 0.017 0.127 34.29 7.1.3 0.013 0.125 34.58 7.1.2 0.017 0.120 34.58 7.1.1 0.003 0.125 16.76 7.1.0 0.007 0.116 16.70
preferences:dark mode live preview
34.27 ms | 403 KiB | 5 Q