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.4.0
0.051253795623779 0.047485113143921 0.042554140090942 0.044015169143677 0.028516054153442
Output for 7.3.12
0.041953086853027 0.038609027862549 0.0329430103302 0.034682989120483 0.022785902023315
Output for 7.3.11
0.061866044998169 0.038043022155762 0.033349990844727 0.040422916412354 0.037384033203125
Output for 7.3.10
0.037283182144165 0.035676956176758 0.032549858093262 0.051186084747314 0.037244081497192
Output for 7.3.9
0.058976888656616 0.042891979217529 0.03200888633728 0.040942192077637 0.035784959793091
Output for 7.3.8
0.036918163299561 0.040942907333374 0.037415027618408 0.041363000869751 0.025506019592285
Output for 7.3.7
0.04413104057312 0.036082029342651 0.032795190811157 0.034510850906372 0.021867036819458
Output for 7.3.6
0.058879852294922 0.039000988006592 0.031205892562866 0.035444974899292 0.02202320098877
Output for 7.3.5
0.037683963775635 0.034953832626343 0.031385898590088 0.032348871231079 0.021636962890625
Output for 7.3.4
0.039471864700317 0.036198139190674 0.03206205368042 0.033028841018677 0.022446870803833
Output for 7.3.3
0.058843851089478 0.044656991958618 0.032553195953369 0.033144950866699 0.022369861602783
Output for 7.3.2
0.039929151535034 0.035292863845825 0.031023979187012 0.033610105514526 0.021850824356079
Output for 7.3.1
0.038293838500977 0.035689115524292 0.030714988708496 0.032515048980713 0.021781921386719
Output for 7.3.0
0.038009881973267 0.036484003067017 0.031960010528564 0.033833026885986 0.02159595489502
Output for 7.2.25
0.063971996307373 0.063248872756958 0.055693864822388 0.056564092636108 0.036504983901978
Output for 7.2.24
0.062685012817383 0.061651229858398 0.054903984069824 0.05590295791626 0.038064956665039
Output for 7.2.23
0.043762922286987 0.041958808898926 0.035094976425171 0.038105010986328 0.024956941604614
Output for 7.2.22
0.048293113708496 0.044461965560913 0.039783000946045 0.042833089828491 0.028396129608154
Output for 7.2.21
0.060680150985718 0.042014837265015 0.033139944076538 0.034502983093262 0.022953987121582
Output for 7.2.20
0.043725967407227 0.041131973266602 0.035390853881836 0.034519910812378 0.023278951644897
Output for 7.2.19
0.039021968841553 0.039959907531738 0.033338069915771 0.032716989517212 0.022414922714233
Output for 7.2.18
0.062186002731323 0.058037996292114 0.037591934204102 0.037140130996704 0.025055170059204
Output for 7.2.17
0.043795108795166 0.040671825408936 0.034755945205688 0.049062013626099 0.037130117416382
Output for 7.2.16
0.043854951858521 0.041314125061035 0.036089897155762 0.036288976669312 0.024184942245483
Output for 7.2.15
0.043584823608398 0.039953947067261 0.035506010055542 0.034460067749023 0.022120952606201
Output for 7.2.14
0.046743869781494 0.044457912445068 0.039253950119019 0.039562225341797 0.02576208114624
Output for 7.2.13
0.039812803268433 0.037639141082764 0.035446166992188 0.034087896347046 0.022741079330444
Output for 7.2.12
0.060548067092896 0.038678884506226 0.033308029174805 0.0326988697052 0.021781921386719
Output for 7.2.11
0.04186487197876 0.038527011871338 0.033926010131836 0.041301965713501 0.033684968948364
Output for 7.2.10
0.044423818588257 0.043666124343872 0.039227962493896 0.038883924484253 0.024653196334839
Output for 7.2.9
0.041538953781128 0.040863990783691 0.03551197052002 0.035463094711304 0.021795988082886
Output for 7.2.8
0.040596961975098 0.037688970565796 0.035681962966919 0.034039974212646 0.021766185760498
Output for 7.2.7
0.042338848114014 0.040388107299805 0.03307318687439 0.032694101333618 0.021833181381226
Output for 7.2.6
0.037557125091553 0.036623001098633 0.030415058135986 0.031937837600708 0.020734071731567
Output for 7.2.5
0.0397629737854 0.036967992782593 0.031857013702393 0.034794092178345 0.036127090454102
Output for 7.2.4
0.040153026580811 0.03610897064209 0.030527114868164 0.03210186958313 0.021754026412964
Output for 7.2.3
0.038697957992554 0.038459062576294 0.031617164611816 0.0347900390625 0.022665977478027
Output for 7.2.2
0.039384126663208 0.036942958831787 0.032634973526001 0.032558917999268 0.021883964538574
Output for 7.2.1
0.051209926605225 0.039302110671997 0.03457498550415 0.032251834869385 0.023256063461304
Output for 7.2.0
0.04124903678894 0.039086103439331 0.033874034881592 0.035531044006348 0.02216911315918
Output for 7.1.33
0.082123041152954 0.064402103424072 0.058974027633667 0.070709943771362 0.047757863998413
Output for 7.1.32
0.079054117202759 0.063138008117676 0.069571971893311 0.063098192214966 0.058465957641602
Output for 7.1.31
0.066869020462036 0.062088012695312 0.057176828384399 0.058326005935669 0.044054985046387
Output for 7.1.30
0.068847179412842 0.084633111953735 0.061406850814819 0.069905996322632 0.060754060745239
Output for 7.1.29
0.067386150360107 0.075628042221069 0.060320138931274 0.05772590637207 0.043781042098999
Output for 7.1.28
0.092289924621582 0.06889796257019 0.063775062561035 0.06340503692627 0.054705142974854
Output for 7.1.27
0.085011005401611 0.06317400932312 0.055341005325317 0.056802034378052 0.04278302192688
Output for 7.1.26
0.065631866455078 0.060985088348389 0.057583093643188 0.056401968002319 0.042906045913696
Output for 7.1.25
0.068222999572754 0.074493169784546 0.059593915939331 0.058254957199097 0.043308019638062
Output for 7.1.12
0.026569128036499 0.0260910987854 0.023787975311279 0.024173974990845 0.019996881484985
Output for 7.1.11
0.027163028717041 0.027786016464233 0.024754047393799 0.024968147277832 0.019365787506104
Output for 7.1.10
0.028234004974365 0.025413990020752 0.024276971817017 0.024445056915283 0.019093990325928
Output for 7.1.9
0.026643037796021 0.026943206787109 0.023591995239258 0.028317928314209 0.019414901733398
Output for 7.1.8
0.026262998580933 0.027080774307251 0.023120164871216 0.02330207824707 0.018908977508545
Output for 7.1.7
0.028800010681152 0.025611162185669 0.024365186691284 0.024157047271729 0.020451068878174
Output for 7.1.6
0.027093887329102 0.025550842285156 0.024270057678223 0.023844957351685 0.01998496055603
Output for 7.1.5
0.025639057159424 0.025228977203369 0.023010015487671 0.02369213104248 0.022097110748291
Output for 7.1.4
0.026180028915405 0.025040149688721 0.025044202804565 0.024264097213745 0.020194053649902
Output for 7.1.3
0.026498079299927 0.025822162628174 0.022566080093384 0.024682998657227 0.018401145935059
Output for 7.1.2
0.026325941085815 0.025099992752075 0.02321195602417 0.02306604385376 0.018589973449707
Output for 7.1.1
0.026548147201538 0.024827003479004 0.022743940353394 0.023888826370239 0.019051074981689
Output for 7.1.0
0.025886058807373 0.02304220199585 0.021929025650024 0.022469043731689 0.017795085906982

preferences:
54.54 ms | 492 KiB | 5 Q