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 = intval($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; $j++) { $oldi = $i; $w = 1; $k = 36; while (isset($nonBasicChars[$j])) { $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, count($output) + 1, $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.0100.00718.56
8.3.50.0120.00521.97
8.3.40.0090.00918.84
8.3.30.0030.01019.15
8.3.20.0000.00820.20
8.3.10.0060.00321.91
8.3.00.0080.00022.44
8.2.180.0070.00716.38
8.2.170.0000.01422.96
8.2.160.0140.00421.07
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0170.00326.16
8.2.120.0000.01317.75
8.2.110.0060.00322.00
8.2.100.0130.00019.64
8.2.90.0000.00819.23
8.2.80.0000.00918.15
8.2.70.0060.00317.75
8.2.60.0050.00518.05
8.2.50.0030.00618.07
8.2.40.0040.00418.34
8.2.30.0030.00518.12
8.2.20.0000.00817.80
8.2.10.0040.00417.83
8.2.00.0050.00317.73
8.1.280.0110.00725.92
8.1.270.0040.00423.99
8.1.260.0080.00026.35
8.1.250.0000.00828.09
8.1.240.0090.00024.02
8.1.230.0100.00319.28
8.1.220.0060.00317.74
8.1.210.0050.00318.77
8.1.200.0090.00017.25
8.1.190.0040.00417.55
8.1.180.0000.00818.73
8.1.170.0060.00318.43
8.1.160.0040.00422.04
8.1.150.0060.00318.74
8.1.140.0050.00517.51
8.1.130.0050.00317.80
8.1.120.0000.00717.42
8.1.110.0040.00417.52
8.1.100.0050.00217.52
8.1.90.0050.00217.49
8.1.80.0040.00417.50
8.1.70.0040.00417.56
8.1.60.0130.00017.57
8.1.50.0000.00917.59
8.1.40.0030.00617.53
8.1.30.0060.00317.75
8.1.20.0000.00917.67
8.1.10.0080.00017.60
8.1.00.0040.00417.61
8.0.300.0030.00518.77
8.0.290.0050.00217.18
8.0.280.0070.00018.66
8.0.270.0000.00817.41
8.0.260.0030.00316.92
8.0.250.0040.00417.05
8.0.240.0100.00017.08
8.0.230.0070.00016.93
8.0.220.0000.00716.98
8.0.210.0030.00316.96
8.0.200.0000.00716.93
8.0.190.0040.00416.97
8.0.180.0040.00416.93
8.0.170.0000.00817.00
8.0.160.0030.00616.89
8.0.150.0000.00716.96
8.0.140.0000.00816.95
8.0.130.0000.00713.41
8.0.120.0040.00416.98
8.0.110.0030.00516.97
8.0.100.0040.00417.08
8.0.90.0050.00216.88
8.0.80.0060.01617.02
8.0.70.0000.00817.04
8.0.60.0000.00716.81
8.0.50.0000.01017.06
8.0.30.0110.00917.26
8.0.20.0130.00517.40
8.0.10.0070.00017.05
8.0.00.0130.00516.82
7.4.330.0020.00215.00
7.4.320.0000.00616.61
7.4.300.0070.00016.66
7.4.290.0000.00916.56
7.4.280.0000.00816.65
7.4.270.0030.00316.47
7.4.260.0070.00016.67
7.4.250.0050.00316.67
7.4.240.0020.00616.62
7.4.230.0030.00316.59
7.4.220.0090.01816.71
7.4.210.0070.00816.62
7.4.200.0030.00416.63
7.4.190.0030.00616.62
7.4.160.0090.00616.68
7.4.150.0150.00317.40
7.4.140.0090.01017.86
7.4.130.0130.00516.58
7.4.120.0110.00616.66
7.4.110.0200.00616.55
7.4.100.0110.00616.42
7.4.90.0070.01016.55
7.4.80.0110.00919.39
7.4.70.0130.00616.55
7.4.60.0080.00816.65
7.4.50.0040.00416.67
7.4.40.0090.00622.77
7.4.30.0150.00716.77
7.4.00.0060.00615.01
7.3.330.0040.00413.38
7.3.320.0030.00313.42
7.3.310.0000.00916.41
7.3.300.0000.00716.36
7.3.290.0090.00616.46
7.3.280.0070.00916.48
7.3.270.0030.01417.40
7.3.260.0130.00416.45
7.3.250.0090.00916.46
7.3.240.0140.00716.68
7.3.230.0190.00516.74
7.3.210.0090.00916.53
7.3.200.0080.00819.39
7.3.190.0100.00716.59
7.3.180.0080.00916.35
7.3.170.0040.01216.61
7.3.160.0170.00416.57
7.3.120.0000.01415.02
7.3.10.0080.00016.50
7.3.00.0050.00516.50
7.2.330.0030.01416.88
7.2.320.0070.01116.88
7.2.310.0030.01816.55
7.2.300.0030.01316.96
7.2.290.0070.01016.79
7.2.130.0070.01016.66
7.2.120.0000.01216.65
7.2.110.0030.00916.55
7.2.100.0070.01016.50
7.2.90.0040.01316.74
7.2.80.0120.00316.75
7.2.70.0090.00316.70
7.2.60.0120.00816.87
7.2.50.0150.00316.52
7.2.40.0100.01016.75
7.2.30.0030.00916.80
7.2.20.0130.00316.70
7.2.10.0160.00416.82
7.2.00.0090.00618.29
7.1.250.0030.00515.86
7.1.100.0180.00818.14
7.1.70.0070.01316.93
7.1.60.0000.02319.82
7.1.50.0160.00716.95
7.1.00.0000.08022.27
7.0.200.0000.00716.52
7.0.140.0000.08022.00
7.0.100.0000.04320.07
7.0.90.0030.04320.10
7.0.80.0000.04320.02
7.0.70.0100.04020.23
7.0.60.0030.04720.12
7.0.50.0070.04020.34
7.0.40.0000.05320.00
7.0.30.0030.04320.04
7.0.20.0000.04720.03
7.0.10.0000.05020.05
7.0.00.0070.04320.10
5.6.280.0030.07321.10
5.6.250.0030.04720.75
5.6.240.0000.04720.74
5.6.230.0030.04320.77
5.6.220.0100.04720.62
5.6.210.0030.04320.62
5.6.200.0030.04321.20
5.6.190.0070.04021.16
5.6.180.0030.05321.09
5.6.170.0100.04321.07
5.6.160.0070.06321.08
5.6.150.0030.03721.16
5.6.140.0030.04021.07
5.6.130.0030.08321.11
5.6.120.0200.07721.16
5.6.110.0070.05321.13
5.6.100.0100.08321.07
5.6.90.0100.08321.15
5.6.80.0070.07720.47
5.6.70.0030.08020.43
5.6.60.0130.07020.54
5.6.50.0100.08020.55
5.6.40.0100.07320.33
5.6.30.0170.07020.46
5.6.20.0030.08020.43
5.6.10.0100.07320.44
5.6.00.0100.06020.42
5.5.380.0070.03320.47
5.5.370.0000.04320.47
5.5.360.0030.05720.39
5.5.350.0030.05020.52
5.5.340.0030.04720.92
5.5.330.0030.04320.94
5.5.320.0100.08320.85
5.5.310.0130.04320.98
5.5.300.0130.07020.89
5.5.290.0170.07320.88
5.5.280.0130.04320.88
5.5.270.0100.08020.87
5.5.260.0130.07720.96
5.5.250.0070.07720.69
5.5.240.0070.07720.34
5.5.230.0070.07720.34
5.5.220.0070.08320.32
5.5.210.0100.07720.32
5.5.200.0130.07020.16
5.5.190.0130.07720.17
5.5.180.0070.05020.16
5.5.160.0030.05720.30
5.5.150.0070.04720.18
5.5.140.0070.06020.27
5.5.130.0100.08020.29
5.5.120.0130.06720.20
5.5.110.0030.08720.27
5.5.100.0070.07720.00
5.5.90.0030.08020.13
5.5.80.0030.08320.21
5.5.70.0070.08020.17
5.5.60.0130.06720.18
5.5.50.0100.05320.13
5.5.40.0100.04320.11
5.5.30.0070.08320.20
5.5.20.0130.07720.14
5.5.10.0070.07720.13
5.5.00.0070.07320.13
5.4.450.0200.06019.42
5.4.440.0170.07019.53
5.4.430.0070.09319.48
5.4.420.0070.08019.17
5.4.410.0030.07719.14
5.4.400.0230.06319.18
5.4.390.0070.05718.95
5.4.380.0030.07719.09
5.4.370.0130.06319.03
5.4.360.0070.05319.23
5.4.350.0030.08019.09
5.4.340.0130.06718.95
5.4.320.0130.08018.85
5.4.310.0100.07318.82
5.4.300.0170.06718.86
5.4.290.0270.06319.23
5.4.280.0070.07719.15
5.4.270.0170.07019.03
5.4.260.0100.06719.13
5.4.250.0100.04319.02
5.4.240.0130.07719.11
5.4.230.0030.08319.04
5.4.220.0030.08319.12
5.4.210.0070.08019.13
5.4.200.0030.07019.15
5.4.190.0100.04718.84
5.4.180.0030.08318.89
5.4.170.0200.03019.13
5.4.160.0130.07019.16
5.4.150.0100.06318.83
5.4.140.0070.07316.44
5.4.130.0130.07016.20
5.4.120.0070.07316.42
5.4.110.0030.04316.32
5.4.100.0070.07716.57
5.4.90.0070.07016.40
5.4.80.0130.06716.31
5.4.70.0100.05016.58
5.4.60.0000.05316.50
5.4.50.0030.07316.46
5.4.40.0100.07016.46
5.4.30.0070.06016.45
5.4.20.0130.06716.53
5.4.10.0130.07316.49
5.4.00.0030.07715.90
5.3.290.0030.06315.70
5.3.280.0070.07315.70
5.3.270.0070.08015.70
5.3.260.0130.07015.70
5.3.250.0070.06015.70
5.3.240.0070.04015.70
5.3.230.0130.07315.70
5.3.220.0070.07715.70
5.3.210.0070.07715.70
5.3.200.0100.07315.70
5.3.190.0070.07715.70
5.3.180.0170.05315.70
5.3.170.0070.07715.70
5.3.160.0070.07715.70
5.3.150.0070.08015.70
5.3.140.0030.05015.70
5.3.130.0000.05315.70
5.3.120.0030.04315.70
5.3.110.0070.07715.70
5.3.100.0130.07015.70
5.3.90.0000.08315.70
5.3.80.0070.06715.70
5.3.70.0070.07315.70
5.3.60.0170.06315.70
5.3.50.0030.07715.70
5.3.40.0070.07715.70
5.3.30.0130.04715.70
5.3.20.0130.05715.70
5.3.10.0230.05715.70
5.3.00.0170.06315.70

preferences:
33.65 ms | 401 KiB | 5 Q