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); if ($count >= 2 && ($input[0] & 0xE0) === 0xC0 && ($input[1] & 0xC0) === 0x80) { $codePoint = (($input[0] & 0x1F) << 6) | ($input[1] & 0x3F); return 2; } else if ($count >= 3 && ($input[0] & 0xF0) === 0xE0 && ($input[1] & 0xC0) === 0x80 && ($input[2] & 0xC0) === 0x80) { $codePoint = (($input[0] & 0x0F) << 12) | (($input[1] & 0x3F) << 6) | ($input[2] & 0x3F); return 3; } else if ($count >= 4 && ($input[0] & 0xF8) === 0xF0 && ($input[1] & 0xC0) === 0x80 && ($input[2] & 0xC0) === 0x80 && ($input[3] & 0xC0) === 0x80) { $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 $ord < 0x010000: return pack('C*', (($codePoint & 0xF000) >> 12) | 0xE0, (($codePoint & 0x0FC0) >> 6) | 0x80, ($codePoint & 0x3F) | 0x80); case $ord < 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 decodeDigit($digit) { if ($digit >= 0x61 && $digit <= 0x7A) { return $digit - 0x61; } else if ($digit >= 0x30 && $digit <= 0x39) { return $digit - 22; } return false; } private function encodeLabel($input) { if (!$this->getEncodingParts($input, $output, $nonBasicChars)) { return false; } if (empty($nonBasicChars)) { return $input; } } 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; do { if (false === $digit = $this->decodeDigit(ord($nonBasicChars[$j++]))) { return false; } if ($k <= $bias) { $t = 1; } else if ($k >= $bias + 26) { $t = 26; } else { $t = $k - $bias; } $i += $digit * $w; $w *= 36 - $t; $k += 36; } while($digit >= $t); $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); } 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--tst-qla.de");

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.0070.01116.63
8.3.50.0120.00721.27
8.3.40.0100.00618.88
8.3.30.0040.01119.05
8.3.20.0000.00820.07
8.3.10.0050.00321.95
8.3.00.0030.00622.37
8.2.180.0070.01118.29
8.2.170.0070.00722.96
8.2.160.0070.00720.51
8.2.150.0120.00424.18
8.2.140.0040.00424.66
8.2.130.0120.00626.16
8.2.120.0080.00019.78
8.2.110.0110.00721.18
8.2.100.0060.00617.97
8.2.90.0030.00519.47
8.2.80.0090.00017.97
8.2.70.0040.00417.63
8.2.60.0030.00518.05
8.2.50.0000.00918.07
8.2.40.0070.00418.22
8.2.30.0040.00418.21
8.2.20.0050.00317.85
8.2.10.0030.00517.73
8.2.00.0030.00517.88
8.1.280.0170.00325.92
8.1.270.0040.00420.52
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0100.00022.32
8.1.230.0130.00018.98
8.1.220.0040.00417.91
8.1.210.0000.00818.77
8.1.200.0060.00317.25
8.1.190.0040.00417.52
8.1.180.0000.00818.74
8.1.170.0030.00618.58
8.1.160.0000.00722.24
8.1.150.0040.00418.66
8.1.140.0080.00017.43
8.1.130.0070.00417.97
8.1.120.0040.00417.60
8.1.110.0030.00517.59
8.1.100.0030.00517.47
8.1.90.0040.00417.52
8.1.80.0040.00417.51
8.1.70.0030.00317.46
8.1.60.0100.00017.67
8.1.50.0030.00517.62
8.1.40.0030.00517.50
8.1.30.0050.00317.75
8.1.20.0000.00817.58
8.1.10.0000.00917.67
8.1.00.0000.00817.46
8.0.300.0080.00018.77
8.0.290.0040.00416.75
8.0.280.0000.00718.48
8.0.270.0040.00417.24
8.0.260.0050.00316.99
8.0.250.0070.00017.09
8.0.240.0020.00517.12
8.0.230.0000.00817.07
8.0.220.0040.00416.99
8.0.210.0030.00316.88
8.0.200.0070.00317.07
8.0.190.0000.00917.12
8.0.180.0000.00717.05
8.0.170.0040.00416.97
8.0.160.0000.00717.01
8.0.150.0040.00416.87
8.0.140.0030.00516.81
8.0.130.0030.00413.36
8.0.120.0040.00417.00
8.0.110.0030.00516.86
8.0.100.0040.00417.04
8.0.90.0030.00516.98
8.0.80.0040.01116.99
8.0.70.0060.00317.02
8.0.60.0050.00316.98
8.0.50.0030.00516.94
8.0.30.0130.00617.27
8.0.20.0100.00917.40
8.0.10.0050.00216.95
8.0.00.0120.00617.00
7.4.330.0020.00215.00
7.4.320.0040.00416.71
7.4.300.0040.00416.59
7.4.290.0040.00416.67
7.4.280.0030.00316.60
7.4.270.0030.00316.66
7.4.260.0040.00416.70
7.4.250.0050.00216.64
7.4.240.0020.00616.64
7.4.230.0000.00716.51
7.4.220.0140.01516.71
7.4.210.0090.00816.71
7.4.200.0030.00516.51
7.4.190.0070.00016.85
7.4.160.0060.01016.81
7.4.150.0090.01517.40
7.4.140.0080.01217.86
7.4.130.0070.01016.62
7.4.120.0100.01016.65
7.4.110.0090.00916.64
7.4.100.0120.00616.72
7.4.90.0100.00716.57
7.4.80.0110.01519.39
7.4.70.0170.00016.60
7.4.60.0100.00716.69
7.4.50.0030.00316.64
7.4.40.0050.00522.77
7.4.30.0030.01416.48
7.4.00.0090.00615.01
7.3.330.0000.00513.44
7.3.320.0050.00013.46
7.3.310.0030.00316.37
7.3.300.0070.00016.47
7.3.290.0080.00816.46
7.3.280.0070.01016.47
7.3.270.0090.00917.40
7.3.260.0140.00716.67
7.3.250.0130.00716.62
7.3.240.0070.01416.38
7.3.230.0080.01816.46
7.3.210.0110.00816.77
7.3.200.0070.01019.39
7.3.190.0030.01516.56
7.3.180.0120.00616.54
7.3.170.0090.01316.59
7.3.160.0090.00616.50
7.3.120.0040.01415.05
7.2.330.0120.00616.79
7.2.320.0120.00716.66
7.2.310.0110.00716.68
7.2.300.0120.00616.54
7.2.290.0050.01116.61
7.2.00.0030.01019.54
7.1.100.0030.00918.19
7.1.70.0060.00916.85
7.1.60.0120.01219.82
7.1.50.0140.00716.84
7.1.00.0000.03722.48
7.0.200.0050.00516.84
7.0.140.0000.06722.09
7.0.100.0300.07020.01
7.0.90.0100.07320.26
7.0.80.0370.04720.05
7.0.70.0200.06319.98
7.0.60.0130.06719.88
7.0.50.0030.07320.43
7.0.40.0000.05020.02
7.0.30.0000.05320.00
7.0.20.0100.06020.03
7.0.10.0130.07720.09
7.0.00.0070.06020.07
5.6.280.0070.07021.08
5.6.250.0100.05320.65
5.6.240.0100.06020.69
5.6.230.0030.05320.68
5.6.220.0030.07020.69
5.6.210.0070.07720.71
5.6.200.0030.05320.99
5.6.190.0100.08021.14
5.6.180.0070.05021.12
5.6.170.0070.09021.17
5.6.160.0030.07021.14
5.6.150.0100.05721.02
5.6.140.0130.06321.07
5.6.130.0130.03721.07
5.6.120.0030.06721.11
5.6.110.0130.04021.11
5.6.100.0030.05021.12
5.6.90.0000.05021.04
5.6.80.0000.04020.41
5.6.70.0100.04020.40
5.6.60.0030.04720.48
5.6.50.0000.03720.38
5.6.40.0100.02720.43
5.6.30.0070.03320.44
5.6.20.0030.04320.48
5.6.10.0100.06720.46
5.6.00.0000.03720.50
5.5.380.0030.07320.42
5.5.370.0100.07720.41
5.5.360.0100.07720.48
5.5.350.0130.06020.48
5.5.340.0070.08020.89
5.5.330.0100.07020.97
5.5.320.0070.07720.95
5.5.310.0100.08020.92
5.5.300.0100.07720.69
5.5.290.0170.04320.88
5.5.280.0000.04720.96
5.5.270.0130.06320.93
5.5.260.0130.04720.85
5.5.250.0030.06720.79
5.5.240.0030.04320.34
5.5.230.0000.05020.21
5.5.220.0070.03720.22
5.5.210.0030.04020.32
5.5.200.0100.03320.29
5.5.190.0070.03020.27
5.5.180.0030.04320.05
5.5.160.0030.03320.16
5.5.150.0030.03320.27
5.5.140.0100.05020.27
5.5.130.0000.03720.20
5.5.120.0000.04320.30
5.5.110.0070.03720.23
5.5.100.0070.04020.04
5.5.90.0070.03320.15
5.5.80.0000.04320.26
5.5.70.0030.04020.14
5.5.60.0070.03320.21
5.5.50.0130.06720.21
5.5.40.0070.04020.11
5.5.30.0000.04020.15
5.5.20.0030.04020.21
5.5.10.0100.03720.08
5.5.00.0000.03720.09
5.4.450.0070.04019.45
5.4.440.0070.08319.27
5.4.430.0070.08019.45
5.4.420.0100.05719.37
5.4.410.0100.04019.32
5.4.400.0070.04719.23
5.4.390.0030.04318.95
5.4.380.0130.03019.21
5.4.370.0000.03718.88
5.4.360.0130.03319.05
5.4.350.0030.03719.03
5.4.340.0070.03019.04
5.4.320.0000.04319.05
5.4.310.0000.04018.95
5.4.300.0000.04019.09
5.4.290.0130.02719.23
5.4.280.0100.04019.08
5.4.270.0070.03319.14
5.4.260.0030.04019.05
5.4.250.0030.04018.84
5.4.240.0000.03319.24
5.4.230.0000.03319.04
5.4.220.0070.05719.02
5.4.210.0030.03718.88
5.4.200.0100.03019.02
5.4.190.0000.04019.02
5.4.180.0030.04019.13
5.4.170.0030.03719.20
5.4.160.0070.03719.19
5.4.150.0000.04319.10
5.4.140.0030.03716.54
5.4.130.0070.03716.47
5.4.120.0030.04016.31
5.4.110.0000.04016.56
5.4.100.0030.03716.49
5.4.90.0000.04016.54
5.4.80.0070.02716.52
5.4.70.0070.03016.47
5.4.60.0130.02716.54
5.4.50.0030.08016.38
5.4.40.0100.03716.51
5.4.30.0030.07716.46
5.4.20.0100.05016.47
5.4.10.0070.03716.37
5.4.00.0170.06016.00
5.3.290.0030.05014.71
5.3.280.0030.03314.55
5.3.270.0070.07714.61
5.3.260.0070.03014.64
5.3.250.0030.03014.66
5.3.240.0030.03314.67
5.3.230.0070.03314.60
5.3.220.0000.03714.59
5.3.210.0030.03714.66
5.3.200.0030.03714.67
5.3.190.0030.03714.72
5.3.180.0070.04714.68
5.3.170.0070.03714.70
5.3.160.0030.07714.66
5.3.150.0170.06714.66
5.3.140.0170.06314.72
5.3.130.0030.08014.68
5.3.120.0070.07714.63
5.3.110.0030.04014.72
5.3.100.0000.05014.08
5.3.90.0070.06314.16
5.3.80.0030.08013.98
5.3.70.0000.07314.14
5.3.60.0100.06314.14
5.3.50.0070.03714.03
5.3.40.0030.07014.00
5.3.30.0000.03713.95
5.3.20.0030.06013.75
5.3.10.0030.06713.57
5.3.00.0070.07313.76

preferences:
36.73 ms | 401 KiB | 5 Q