3v4l.org

run code in 300+ PHP versions simultaneously
<?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;
Output for 7.3.1
0.07037091255188 0.064385890960693 0.06023097038269 0.057279109954834 0.034147024154663
Output for 7.3.0
0.072225093841553 0.050918102264404 0.04554009437561 0.049394845962524 0.036001920700073
Output for 7.2.13
0.057777881622314 0.054084062576294 0.055346965789795 0.049213886260986 0.033041954040527
Output for 7.2.12
0.074662923812866 0.05569314956665 0.048771858215332 0.047237873077393 0.032393932342529
Output for 7.2.11
0.056910037994385 0.052093029022217 0.05401611328125 0.048494100570679 0.032690048217773
Output for 7.2.10
0.066730976104736 0.066076993942261 0.055376052856445 0.055344104766846 0.037137985229492
Output for 7.2.9
0.059627056121826 0.069885969161987 0.05712890625 0.047761917114258 0.042068004608154
Output for 7.2.8
0.073106050491333 0.060776948928833 0.053340911865234 0.053344011306763 0.038156986236572
Output for 7.2.7
0.14697694778442 0.066581010818481 0.047395944595337 0.048849105834961 0.032580137252808
Output for 7.2.6
0.18211102485657 0.053423166275024 0.048066854476929 0.047706127166748 0.039142847061157
Output for 7.2.5
0.06190299987793 0.053431034088135 0.047566890716553 0.057787895202637 0.046772003173828
Output for 7.2.4
0.085070848464966 0.051532030105591 0.055905818939209 0.065239191055298 0.031812906265259
Output for 7.2.3
0.080939054489136 0.056265830993652 0.055820941925049 0.049721956253052 0.032915830612183
Output for 7.2.2
0.076762914657593 0.06007719039917 0.049368858337402 0.053260087966919 0.041945934295654
Output for 7.2.1
0.06926703453064 0.063697099685669 0.047912120819092 0.048005104064941 0.033601999282837
Output for 7.2.0
0.06138801574707 0.056196928024292 0.053658008575439 0.056517124176025 0.035048961639404
Output for 7.1.25
0.10845804214478 0.096422910690308 0.10247993469238 0.084295988082886 0.060940027236938
Output for 7.1.12
0.04833984375 0.037122964859009 0.032186031341553 0.032764911651611 0.027817010879517
Output for 7.1.11
0.042786836624146 0.048964977264404 0.038249969482422 0.031885147094727 0.025214910507202
Output for 7.1.10
0.039655923843384 0.03714394569397 0.030825138092041 0.031333208084106 0.025250196456909
Output for 7.1.9
0.038611888885498 0.036925077438354 0.043833017349243 0.036026000976562 0.025525093078613
Output for 7.1.8
0.044021129608154 0.035377025604248 0.030749082565308 0.030416965484619 0.02682900428772
Output for 7.1.7
0.037114143371582 0.037825107574463 0.031881093978882 0.031790018081665 0.027379035949707
Output for 7.1.6
0.035202026367188 0.034565925598145 0.032083988189697 0.033287048339844 0.027959108352661
Output for 7.1.5
0.054455995559692 0.040096998214722 0.038925886154175 0.038254022598267 0.026037216186523
Output for 7.1.4
0.032731056213379 0.031485080718994 0.028933048248291 0.031707048416138 0.027335166931152
Output for 7.1.3
0.037060976028442 0.032392978668213 0.038975954055786 0.029762029647827 0.024139165878296
Output for 7.1.2
0.03333592414856 0.033483028411865 0.030390024185181 0.029749155044556 0.024880886077881
Output for 7.1.1
0.031654119491577 0.032323837280273 0.029175996780396 0.035950183868408 0.023930072784424
Output for 7.1.0
0.03256893157959 0.032569885253906 0.029236078262329 0.027781009674072 0.023009061813354

preferences:
65.13 ms | 401 KiB | 35 Q