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.4.00.0070.22215.00
7.3.120.0070.17614.85
7.3.110.0030.22314.86
7.3.100.0070.20014.80
7.3.90.0070.21414.86
7.3.80.0070.18914.81
7.3.70.0100.17114.84
7.3.60.0030.19315.05
7.3.50.0000.17014.65
7.3.40.0100.16714.64
7.3.30.0070.19514.95
7.3.20.0000.17116.77
7.3.10.0070.16616.33
7.3.00.0070.16616.33
7.2.250.0000.29115.39
7.2.240.0100.28015.19
7.2.230.0030.19315.14
7.2.220.0030.21515.00
7.2.210.0030.20014.84
7.2.200.0130.17815.21
7.2.190.0030.17815.09
7.2.180.0000.23115.07
7.2.170.0070.21215.23
7.2.160.0070.19015.31
7.2.150.0100.17917.02
7.2.140.0000.21117.05
7.2.130.0000.18017.00
7.2.120.0030.19417.00
7.2.110.0000.19816.84
7.2.100.0070.19916.92
7.2.90.0030.18617.09
7.2.80.0030.18016.97
7.2.70.0070.17316.68
7.2.60.0070.16116.93
7.2.50.0100.18317.13
7.2.40.0000.17017.10
7.2.30.0000.18016.85
7.2.20.0070.17317.04
7.2.10.0100.18217.02
7.2.00.0050.13618.31
7.1.330.0030.33015.89
7.1.320.0030.34015.87
7.1.310.0000.30215.87
7.1.300.0030.35215.96
7.1.290.0070.31015.81
7.1.280.0070.34615.74
7.1.270.0030.30915.76
7.1.260.0000.29115.80
7.1.250.0070.31016.03
7.1.120.0030.12818.70
7.1.110.0070.12618.15
7.1.100.0070.12618.33
7.1.90.0070.12918.12
7.1.80.0070.12317.96
7.1.70.0040.13317.20
7.1.60.0170.12635.26
7.1.50.0140.12935.01
7.1.40.0170.12734.29
7.1.30.0130.12534.58
7.1.20.0170.12034.58
7.1.10.0030.12516.76
7.1.00.0070.11616.70

preferences:
34.27 ms | 403 KiB | 5 Q