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;

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).

VersionSystem time (s)User time (s)Memory (MiB)
7.3.10.0130.29516.21
7.3.00.0140.26516.39
7.2.130.0100.25416.17
7.2.120.0100.24816.38
7.2.110.0170.24816.95
7.2.100.0100.29216.73
7.2.90.0120.28316.41
7.2.80.0190.27416.56
7.2.70.0070.28416.64
7.2.60.0070.28116.05
7.2.50.0130.27216.66
7.2.40.0070.27416.73
7.2.30.0070.26316.19
7.2.20.0070.28016.41
7.2.10.0070.27116.79
7.2.00.0030.20318.34
7.1.250.0150.45215.63
7.1.120.0030.17618.69
7.1.110.0030.19117.92
7.1.100.0030.17018.16
7.1.90.0030.18918.04
7.1.80.0000.18018.12
7.1.70.0000.17717.15
7.1.60.0170.17135.15
7.1.50.0230.19734.93
7.1.40.0130.16434.44
7.1.30.0100.17934.47
7.1.20.0100.16434.40
7.1.10.0100.15016.44
7.1.00.0060.15016.62

preferences:
29.95 ms | 401 KiB | 5 Q