3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Punycode { private function decodeUtf8Character($input, $i, &$codePoint = null) { $input = array_values(unpack('C*', substr($input, $i, 4))); $count = count($input); switch (true) { case $count >= 2 && ($input[0] & 0xE0) === 0xC0 && ($input[1] & 0xC0) === 0x80: $codePoint = (($input[0] & 0x1F) << 6) | ($input[1] & 0x3F); return 2; case $count >= 3 && ($input[0] & 0xF0) === 0xE0 && (($input[1] ^ 0x40) & ($input[2] ^ 0x40) & 0xC0) === 0xC0: $codePoint = (($input[0] & 0x0F) << 12) | (($input[1] & 0x3F) << 6) | ($input[2] & 0x3F); return 3; case $count >= 4 && ($input[0] & 0xF8) === 0xF0 && (($input[1] ^ 0x40) & ($input[2] ^ 0x40) & ($input[3] ^ 0x40) & 0xC0) === 0xC0: $codePoint = (($input[0] & 0x07) << 18) | (($input[1] & 0x3F) << 12) | (($input[2] & 0x3F) << 6) | ($input[3] & 0x3F); return 4; } return 0; } private function encodeUtf8CodePoint($codePoint) { switch (true) { case $codePoint < 0x80: return pack('C*', $codePoint & 0x7F); case $codePoint < 0x0800: return pack('C*', (($codePoint & 0x07C0) >> 6) | 0xC0, ($codePoint & 0x3F) | 0x80); case $codePoint < 0x010000: return pack('C*', (($codePoint & 0xF000) >> 12) | 0xE0, (($codePoint & 0x0FC0) >> 6) | 0x80, ($codePoint & 0x3F) | 0x80); case $codePoint < 0x110000: return pack('C*', (($codePoint & 0x1C0000) >> 18) | 0xF0, (($codePoint & 0x03F000) >> 12) | 0x80, (($codePoint & 0x0FC0) >> 6) | 0x80, ($codePoint & 0x3F) | 0x80); } return false; } private function isDnsLabelChar($charCode) { return ($charCode >= 0x61 && $charCode <= 0x7A) // lower-case letter || ($charCode >= 0x30 && $charCode <= 0x39) // digit || $charCode === 0x2D // - || ($charCode >= 0x41 && $charCode <= 0x5A); // upper-case letter; } private function isPrintableLatin1Char($charCode) { return $charCode >= 0xA0; } private function getEncodingParts($input, &$output = [], &$nonBasicChars = []) { $isUtf8 = true; for ($i = $p = 0, $l = strlen($input); $i < $l; $p++) { $charCode = ord($input[$i]); if ($charCode & 0x80) { if ($isUtf8) { if ($len = $this->decodeUtf8Character($input, $i, $codePoint)) { $nonBasicChars[] = [$p, $codePoint, substr($input, $i, $len), $len]; // undecoded data is stored for UTF-8 chars to facilitate conversion to latin1 if necessary $i += $len; } else { // not a valid UTF-8 code point, convert $nonBasicChars to latin1 representation if (!$this->isPrintableLatin1Char($charCode)) { return false; } $isUtf8 = false; if (!empty($nonBasicChars)) { $offset = 0; for ($j = 0, $l = count($nonBasicChars); $j < $l; $j++) { $base = $nonBasicChars[$j][0]; $nonBasicChars[$j][0] += $offset; $nonBasicChars[$j][1] = ord($nonBasicChars[$j][2][0]); for ($k = 1; $k < $nonBasicChars[$j][3]; $k++) { $nonBasicChars[] = [$base + ++$offset, ord($nonBasicChars[$j][2][$k])]; } } $nonBasicChars[] = [$i++, $charCode]; usort($nonBasicChars, function($a, $b) { return $a[0] - $b[0]; }); } else { $nonBasicChars[] = [$i++, $charCode]; } } } else if ($this->isPrintableLatin1Char($charCode)) { $nonBasicChars[] = [$i++, $charCode]; } else { return false; } } else if ($this->isDnsLabelChar($charCode)) { $output[] = $input[$i++]; } else { return false; } } return true; } private function adaptBias($delta, $numPoints, $first) { $delta = $first ? $delta / 700 : $delta / 2; $delta += $delta / $numPoints; for ($k = 0; $delta > 455; $k += 36) { $delta = (int) ($delta / 35); } return $k + (36 * $delta) / ($delta + 38); } private function decodeLabel($input) { if (substr($input, 0, 4) !== 'xn--') { return $input; } $input = substr($input, 4); if (false !== $nonBasicCharsStart = strrpos($input, '-')) { $nonBasicChars = substr($input, $nonBasicCharsStart + 1); $output = str_split(substr($input, 0, $nonBasicCharsStart), 1); } else { $nonBasicChars = $input; $output = []; } $n = 128; $i = 0; $bias = 72; for ($j = 0, $l = strlen($nonBasicChars); $j < $l;) { $oldi = $i; $w = 1; $k = 36; while (true) { if (!isset($nonBasicChars[$j])) { return false; } $digit = ord($nonBasicChars[$j++]); if ($digit >= 0x61 && $digit <= 0x7A) { $digit -= 97; } else if ($digit >= 0x30 && $digit <= 0x39) { $digit -= 22; } else { return false; } $i += $digit * $w; if ($k <= $bias) { $t = 1; } else if ($k >= $bias + 26) { $t = 26; } else { $t = $k - $bias; } if ($digit < $t) { break; } $w *= 36 - $t; $k += 36; } $c = count($output) + 1; $bias = $this->adaptBias($i - $oldi, $c, $oldi === 0); $n += (int) ($i / $c); $i %= $c; array_splice($output, $i, 0, $this->encodeUtf8CodePoint($n)); $i++; } return implode('', $output); } private function encodeLabel($input) { if (!$this->getEncodingParts($input, $output, $nonBasicChars)) { return false; } if (empty($nonBasicChars)) { return $input; } $output = 'xn--' . $output; } public function decode($input) { $output = []; foreach (explode('.', strtolower($input)) as $label) { if (false === $label = $this->decodeLabel($label)) { return false; } $output[] = $label; } return implode('.', $output); } public function encode($input) { $output = []; foreach (explode('.', strtolower($input)) as $label) { if (false === $label = $this->encodeLabel($label)) { return false; } $output[] = $label; } return implode('.', $output); } } echo (new Punycode)->decode("xn---with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n");

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)
8.3.60.0160.00618.68
8.3.50.0060.01322.05
8.3.40.0000.01518.84
8.3.30.0150.00018.79
8.3.20.0040.00418.76
8.3.10.0040.00421.18
8.3.00.0040.00423.65
8.2.180.0060.00916.75
8.2.170.0110.00722.96
8.2.160.0110.00320.66
8.2.150.0080.00024.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0040.00421.00
8.2.110.0090.00020.84
8.2.100.0090.00317.97
8.2.90.0000.00819.34
8.2.80.0030.00717.97
8.2.70.0030.00517.75
8.2.60.0050.00518.05
8.2.50.0000.00918.10
8.2.40.0040.00418.16
8.2.30.0060.00319.64
8.2.20.0040.00417.75
8.2.10.0040.00417.83
8.2.00.0060.00617.84
8.1.280.0060.01225.92
8.1.270.0080.00023.99
8.1.260.0170.00326.35
8.1.250.0080.00028.09
8.1.240.0000.00919.64
8.1.230.0040.00717.95
8.1.220.0000.00817.80
8.1.210.0050.00318.77
8.1.200.0070.00317.48
8.1.190.0040.00417.35
8.1.180.0000.00818.10
8.1.170.0040.00418.63
8.1.160.0060.00318.95
8.1.150.0000.00818.68
8.1.140.0080.00017.55
8.1.130.0000.00717.93
8.1.120.0000.00717.62
8.1.110.0030.00517.51
8.1.100.0040.00417.59
8.1.90.0000.00717.48
8.1.80.0000.00817.46
8.1.70.0020.00517.50
8.1.60.0000.01117.68
8.1.50.0030.00617.58
8.1.40.0040.00417.64
8.1.30.0040.00417.59
8.1.20.0000.00817.69
8.1.10.0040.00417.59
8.1.00.0000.00817.63
8.0.300.0060.00318.77
8.0.290.0000.00916.88
8.0.280.0000.00718.55
8.0.270.0040.00417.39
8.0.260.0030.00316.92
8.0.250.0050.00217.15
8.0.240.0040.00417.02
8.0.230.0000.00717.13
8.0.220.0070.00016.95
8.0.210.0050.00217.01
8.0.200.0000.00716.96
8.0.190.0040.00417.16
8.0.180.0040.00417.05
8.0.170.0100.00017.15
8.0.160.0030.00516.99
8.0.150.0050.00216.98
8.0.140.0000.00717.00
8.0.130.0060.00013.46
8.0.120.0030.00616.95
8.0.110.0040.00416.98
8.0.100.0050.00316.93
8.0.90.0000.00817.00
8.0.80.0030.01217.09
8.0.70.0060.00316.91
8.0.60.0040.00416.91
8.0.50.0000.00817.12
8.0.30.0100.00917.47
8.0.20.0080.01617.40
8.0.10.0050.00317.21
8.0.00.0080.00817.08
7.4.330.0000.00516.77
7.4.320.0000.00616.72
7.4.300.0030.00316.56
7.4.290.0030.00316.63
7.4.280.0040.00416.69
7.4.270.0070.00016.55
7.4.260.0030.00313.38
7.4.250.0030.00616.67
7.4.240.0040.00416.56
7.4.230.0000.00716.60
7.4.220.0060.01016.50
7.4.210.0060.00816.66
7.4.200.0000.00716.79
7.4.190.0070.00016.75
7.4.160.0100.00716.74
7.4.150.0060.01217.40
7.4.140.0090.00917.86
7.4.130.0140.00616.62
7.4.120.0100.01016.68
7.4.110.0100.01616.57
7.4.100.0040.01316.59
7.4.90.0030.01416.64
7.4.80.0070.01419.39
7.4.70.0120.00616.60
7.4.60.0130.00316.52
7.4.50.0060.00316.48
7.4.40.0060.01022.77
7.4.30.0070.01516.71
7.4.00.0100.00715.16
7.3.330.0000.00613.36
7.3.320.0000.00813.49
7.3.310.0040.00416.58
7.3.300.0000.00716.54
7.3.290.0090.00616.52
7.3.280.0070.00816.57
7.3.270.0090.00917.40
7.3.260.0120.00818.24
7.3.250.0090.00916.53
7.3.240.0070.01016.73
7.3.230.0070.01716.70
7.3.210.0070.01016.44
7.3.200.0060.00819.39
7.3.190.0090.01016.73
7.3.180.0070.01016.43
7.3.170.0080.00816.57
7.3.160.0100.01416.65
7.3.120.0000.01015.01
7.2.330.0070.01716.89
7.2.320.0130.01016.87
7.2.310.0110.00816.86
7.2.300.0160.00316.90
7.2.290.0030.01416.68
7.2.60.0060.00916.92
7.2.00.0030.01319.61
7.1.200.0070.00715.68
7.1.100.0030.00918.18
7.1.70.0040.00417.22
7.1.60.0030.02019.08
7.1.50.0110.01416.93
7.1.00.0070.05022.28
7.0.200.0030.00616.82
7.0.140.0030.07322.10
7.0.100.0100.07020.13
7.0.90.0070.08320.02
7.0.80.0270.05320.25
7.0.70.0230.08319.98
7.0.60.0130.07720.18
7.0.50.0000.08020.49
7.0.40.0070.08020.19
7.0.30.0070.08319.93
7.0.20.0070.08320.12
7.0.10.0070.08320.17
7.0.00.0030.09020.09
5.6.280.0030.07321.09
5.6.250.0130.07320.72
5.6.240.0100.05720.75
5.6.230.0100.08020.66
5.6.220.0130.07320.68
5.6.210.0000.09020.80
5.6.200.0100.07321.11
5.6.190.0130.08021.05
5.6.180.0070.06721.10
5.6.170.0000.05721.00
5.6.160.0070.08321.13
5.6.150.0070.07321.14
5.6.140.0070.05721.00
5.6.130.0030.07721.17
5.6.120.0130.08321.09
5.6.110.0030.04321.13
5.6.100.0030.07321.00
5.6.90.0030.04321.13
5.6.80.0070.07720.40
5.6.70.0070.07720.52
5.6.60.0030.07720.45
5.6.50.0070.07020.62
5.6.40.0070.07720.59
5.6.30.0030.08020.52
5.6.20.0100.07320.47
5.6.10.0030.08720.45
5.6.00.0030.05320.46
5.5.380.0000.08020.41
5.5.370.0030.05020.41
5.5.360.0070.07320.40
5.5.350.0070.08320.49
5.5.340.0000.05720.87
5.5.330.0130.07320.98
5.5.320.0200.06320.89
5.5.310.0100.04720.88
5.5.300.0030.09020.96
5.5.290.0070.06320.70
5.5.280.0130.05020.94
5.5.270.0070.08320.82
5.5.260.0070.07720.96
5.5.250.0130.07020.77
5.5.240.0030.05020.34
5.5.230.0000.07320.36
5.5.220.0130.07720.23
5.5.210.0030.07320.06
5.5.200.0200.07320.30
5.5.190.0070.08020.20
5.5.180.0100.07720.32
5.5.160.0030.08320.28
5.5.150.0030.05020.29
5.5.140.0100.06720.30
5.5.130.0070.06020.29
5.5.120.0030.04320.33
5.5.110.0100.07020.27
5.5.100.0100.06320.19
5.5.90.0100.07320.03
5.5.80.0170.05720.18
5.5.70.0030.06720.09
5.5.60.0000.08320.11
5.5.50.0100.06020.21
5.5.40.0070.08020.12
5.5.30.0030.08320.20
5.5.20.0100.07720.09
5.5.10.0130.06720.15
5.5.00.0070.04720.03
5.4.450.0130.07319.51
5.4.440.0070.08019.27
5.4.430.0100.08019.32
5.4.420.0070.08019.35
5.4.410.0070.07319.05
5.4.400.0100.05719.16
5.4.390.0130.07019.14
5.4.380.0070.07319.21
5.4.370.0070.04019.16
5.4.360.0070.09719.14
5.4.350.0130.07719.19
5.4.340.0070.06719.21
5.4.320.0100.07319.21
5.4.310.0070.07018.87
5.4.300.0030.03719.12
5.4.290.0070.07319.03
5.4.280.0030.07719.00
5.4.270.0030.06319.05
5.4.260.0030.03719.04
5.4.250.0070.03319.04
5.4.240.0000.07719.23
5.4.230.0130.05319.20
5.4.220.0100.07019.21
5.4.210.0030.04319.03
5.4.200.0130.07019.03
5.4.190.0070.07319.02
5.4.180.0170.05018.87
5.4.170.0030.04019.04
5.4.160.0100.06718.86
5.4.150.0100.05019.03
5.4.140.0070.05716.52
5.4.130.0100.06016.39
5.4.120.0100.07016.50
5.4.110.0070.04016.57
5.4.100.0070.07316.32
5.4.90.0030.04716.56
5.4.80.0070.04316.38
5.4.70.0100.06716.53
5.4.60.0070.06716.38
5.4.50.0130.07016.42
5.4.40.0000.05716.46
5.4.30.0000.08016.42
5.4.20.0070.04716.51
5.4.10.0070.07316.51
5.4.00.0170.04315.96
5.3.290.0030.05314.80
5.3.280.0030.04014.62
5.3.270.0070.03714.71
5.3.260.0100.05014.59
5.3.250.0000.05314.62
5.3.240.0070.08014.62
5.3.230.0130.07314.53
5.3.220.0000.07714.71
5.3.210.0100.06714.74
5.3.200.0100.04014.61
5.3.190.0000.08314.58
5.3.180.0030.05314.53
5.3.170.0030.06714.58
5.3.160.0070.03314.63
5.3.150.0030.05714.60
5.3.140.0100.06314.65
5.3.130.0100.04314.56
5.3.120.0030.08014.61
5.3.110.0070.05014.57
5.3.100.0070.06314.13
5.3.90.0100.06014.18
5.3.80.0030.05314.03
5.3.70.0070.07014.08
5.3.60.0030.04314.03
5.3.50.0000.08314.00
5.3.40.0170.05713.91
5.3.30.0070.05713.95
5.3.20.0100.06713.76
5.3.10.0130.06313.61
5.3.00.0130.05313.66
5.2.170.0030.04311.28
5.2.160.0070.03311.21
5.2.150.0030.06311.17
5.2.140.0070.06011.21
5.2.130.0000.06011.18
5.2.120.0030.05711.02
5.2.110.0000.03711.24
5.2.100.0100.02711.20
5.2.90.0130.04711.28
5.2.80.0070.04011.25
5.2.70.0070.03011.26
5.2.60.0100.06011.08
5.2.50.0070.05011.20
5.2.40.0000.05011.16
5.2.30.0070.05311.13
5.2.20.0030.05711.07
5.2.10.0070.04711.00
5.2.00.0030.04010.81
5.1.60.0070.04010.14
5.1.50.0070.05010.13
5.1.40.0000.04710.13
5.1.30.0070.03010.23
5.1.20.0030.05310.50
5.1.10.0030.05010.21
5.1.00.0000.03010.18
5.0.50.0070.0438.70
5.0.40.0000.0308.30
5.0.30.0030.0638.16
5.0.20.0070.0408.36
5.0.10.0030.0438.31
5.0.00.0100.0478.22
4.4.90.0000.0377.80
4.4.80.0000.0377.80
4.4.70.0030.0337.80
4.4.60.0030.0207.80
4.4.50.0030.0277.80
4.4.40.0030.0437.80
4.4.30.0000.0207.80
4.4.20.0070.0137.80
4.4.10.0000.0377.80
4.4.00.0070.0477.80
4.3.110.0000.0377.80
4.3.100.0070.0337.80
4.3.90.0070.0137.80
4.3.80.0100.0507.80
4.3.70.0070.0307.80
4.3.60.0030.0207.80
4.3.50.0000.0307.80
4.3.40.0000.0307.80
4.3.30.0000.0377.80
4.3.20.0000.0377.80
4.3.10.0030.0237.80
4.3.00.0000.0307.80

preferences:
50.68 ms | 401 KiB | 5 Q