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; do { $digit = ord($nonBasicChars[$j++]); if ($digit >= 0x61 && $digit <= 0x7A) { $digit -= 97; } else if ($digit >= 0x30 && $digit <= 0x39) { $digit -= 22; } else { 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); } 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--Hello-Another-Way--fc4qua05auwb3674vfr0b");

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.00718.31
8.3.50.0130.00318.93
8.3.40.0070.00718.97
8.3.30.0080.00818.84
8.3.20.0000.00818.91
8.3.10.0050.00320.53
8.3.00.0050.00319.50
8.2.180.0060.01316.75
8.2.170.0140.00422.96
8.2.160.0030.01022.13
8.2.150.0040.00424.18
8.2.140.0060.00324.66
8.2.130.0070.00326.16
8.2.120.0060.00319.85
8.2.110.0040.00721.07
8.2.100.0120.00018.03
8.2.90.0050.00319.47
8.2.80.0040.00418.18
8.2.70.0000.00817.88
8.2.60.0040.00418.05
8.2.50.0080.00018.07
8.2.40.0080.00018.17
8.2.30.0030.00618.33
8.2.20.0030.00517.74
8.2.10.0000.00817.86
8.2.00.0000.00817.90
8.1.280.0060.01025.92
8.1.270.0080.00023.99
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0060.00320.95
8.1.230.0040.00821.03
8.1.220.0000.00917.91
8.1.210.0050.00319.10
8.1.200.0070.00317.35
8.1.190.0050.00317.55
8.1.180.0000.00918.10
8.1.170.0110.00018.90
8.1.160.0030.00518.91
8.1.150.0000.00818.80
8.1.140.0070.00017.49
8.1.130.0040.00417.83
8.1.120.0040.00417.50
8.1.110.0060.00317.55
8.1.100.0050.00217.56
8.1.90.0000.00717.54
8.1.80.0040.00417.50
8.1.70.0040.00417.48
8.1.60.0060.00317.72
8.1.50.0000.00917.61
8.1.40.0000.00817.63
8.1.30.0030.00617.71
8.1.20.0040.00417.72
8.1.10.0040.00417.64
8.1.00.0030.00617.59
8.0.300.0070.00020.10
8.0.290.0040.00416.88
8.0.280.0030.00518.52
8.0.270.0040.00417.42
8.0.260.0070.00016.92
8.0.250.0040.00417.02
8.0.240.0060.00317.07
8.0.230.0100.00016.96
8.0.220.0000.00817.00
8.0.210.0050.00516.89
8.0.200.0000.00616.97
8.0.190.0040.00416.94
8.0.180.0050.00316.99
8.0.170.0000.00916.99
8.0.160.0040.00416.98
8.0.150.0090.00016.81
8.0.140.0000.01116.86
8.0.130.0000.00713.40
8.0.120.0000.00716.84
8.0.110.0080.00016.88
8.0.100.0040.00416.99
8.0.90.0040.00416.82
8.0.80.0090.00616.94
8.0.70.0030.00516.96
8.0.60.0040.00416.87
8.0.50.0040.00417.00
8.0.30.0050.01417.01
8.0.20.0090.01017.40
8.0.10.0070.00017.18
8.0.00.0110.01116.73
7.4.330.0000.00513.43
7.4.320.0060.00016.61
7.4.300.0030.00316.71
7.4.290.0070.00016.67
7.4.280.0000.00816.69
7.4.270.0040.00416.66
7.4.260.0060.00013.40
7.4.250.0060.00316.69
7.4.240.0030.00516.55
7.4.230.0050.00216.68
7.4.220.0070.01116.75
7.4.210.0090.00616.69
7.4.200.0070.00016.50
7.4.190.0000.00716.79
7.4.160.0060.01016.73
7.4.150.0130.00617.40
7.4.140.0070.01117.27
7.4.130.0120.00516.79
7.4.120.0080.01316.63
7.4.110.0130.00316.40
7.4.100.0030.02116.52
7.4.90.0180.00016.76
7.4.80.0060.01219.03
7.4.70.0030.01316.39
7.4.60.0060.01216.66
7.4.50.0000.00516.53
7.4.40.0140.00322.27
7.4.30.0030.01716.57
7.4.00.0040.01315.12
7.3.330.0070.00013.34
7.3.320.0070.00013.45
7.3.310.0000.00816.38
7.3.300.0000.00816.47
7.3.290.0080.00816.46
7.3.280.0080.01016.45
7.3.270.0060.01117.40
7.3.260.0080.01418.24
7.3.250.0080.01216.63
7.3.240.0060.01216.60
7.3.230.0110.00716.78
7.3.210.0160.00416.73
7.3.200.0090.00919.39
7.3.190.0130.00916.84
7.3.180.0150.00616.42
7.3.170.0180.00016.59
7.3.160.0060.00916.69
7.3.120.0090.00814.94
7.3.110.0030.01414.93
7.3.100.0060.00814.99
7.3.90.0040.01214.86
7.3.80.0050.01015.00
7.3.70.0050.01114.89
7.3.60.0060.00714.89
7.3.50.0060.01014.76
7.3.40.0030.01014.85
7.3.30.0030.01114.72
7.3.20.0110.00616.56
7.3.10.0090.00716.80
7.3.00.0100.00716.66
7.2.330.0140.00616.54
7.2.320.0150.00316.89
7.2.310.0210.00016.62
7.2.300.0120.00616.99
7.2.290.0130.00316.70
7.2.250.0050.01315.21
7.2.240.0120.00815.07
7.2.230.0040.01115.07
7.2.220.0050.00915.29
7.2.210.0070.00915.12
7.2.200.0100.00515.28
7.2.190.0080.00815.24
7.2.180.0090.00515.16
7.2.170.0050.01115.00
7.2.160.0000.01315.14
7.2.150.0140.00316.83
7.2.140.0040.01516.86
7.2.130.0100.00717.03
7.2.120.0030.01316.92
7.2.110.0110.00716.98
7.2.100.0060.00916.79
7.2.90.0080.00317.04
7.2.80.0110.00417.16
7.2.70.0030.01016.82
7.2.60.0060.00917.09
7.2.50.0110.00316.99
7.2.40.0080.00417.06
7.2.30.0060.01016.98
7.2.20.0030.01216.85
7.2.10.0030.01017.09
7.2.00.0080.00817.98
7.1.330.0050.01115.82
7.1.320.0070.00915.68
7.1.310.0070.00915.81
7.1.300.0060.01015.64
7.1.290.0030.00715.88
7.1.280.0020.01215.79
7.1.270.0050.01115.85
7.1.260.0040.01515.78
7.1.250.0030.00715.88
7.1.240.0040.01115.76
7.1.230.0030.00815.66
7.1.220.0070.00415.94
7.1.210.0000.01515.67
7.1.200.0070.00715.93
7.1.190.0090.00615.78
7.1.180.0060.00615.59
7.1.170.0080.00815.92
7.1.160.0070.00715.96
7.1.150.0030.00715.54
7.1.140.0120.00315.59
7.1.130.0060.00615.82
7.1.120.0080.00815.64
7.1.110.0060.00615.92
7.1.100.0040.00916.96
7.1.90.0050.00815.91
7.1.80.0030.01215.79
7.1.70.0090.00716.54
7.1.60.0090.00817.63
7.1.50.0080.00816.55
7.1.40.0080.00615.69
7.1.30.0000.01115.85
7.1.20.0080.00415.90
7.1.10.0040.01215.65
7.1.00.0050.04219.16
7.0.330.0130.00015.40
7.0.320.0120.00315.49
7.0.310.0040.00715.27
7.0.300.0030.00615.38
7.0.290.0080.00315.40
7.0.280.0070.00715.49
7.0.270.0040.01115.43
7.0.260.0000.00915.43
7.0.250.0000.01015.59
7.0.240.0080.00815.59
7.0.230.0030.01315.48
7.0.220.0000.01315.44
7.0.210.0070.00415.41
7.0.200.0000.01216.12
7.0.190.0100.00715.24
7.0.180.0090.00015.54
7.0.170.0040.00715.24
7.0.160.0030.01015.25
7.0.150.0090.00615.38
7.0.140.0070.04018.74
7.0.130.0070.00715.60
7.0.120.0060.00615.48
7.0.110.0100.00615.50
7.0.100.0060.04117.65
7.0.90.0050.04517.65
7.0.80.0160.01617.65
7.0.70.0070.04217.75
7.0.60.0110.04117.81
7.0.50.0070.03117.95
7.0.40.0100.04216.73
7.0.30.0080.02216.64
7.0.20.0070.03316.83
7.0.10.0120.03516.80
7.0.00.0070.04016.79
5.6.400.0090.00914.74
5.6.390.0060.00614.87
5.6.380.0090.00614.74
5.6.370.0030.01014.48
5.6.360.0070.00714.18
5.6.350.0040.01114.28
5.6.340.0030.01014.18
5.6.330.0030.01214.22
5.6.320.0070.00714.40
5.6.310.0000.01414.69
5.6.300.0040.00714.85
5.6.290.0030.01314.11
5.6.280.0030.00914.68
5.6.270.0090.00614.36
5.6.260.0100.00314.18
5.6.250.0060.04817.66
5.6.240.0050.02317.68
5.6.230.0070.02217.68
5.6.220.0070.04217.67
5.6.210.0060.03217.63
5.6.200.0050.02717.87
5.6.190.0040.04817.84
5.6.180.0040.04217.85
5.6.170.0000.04117.88
5.6.160.0100.03517.79
5.6.150.0060.04717.82
5.6.140.0120.03017.71
5.6.130.0060.03617.81
5.6.120.0080.04618.05
5.6.110.0050.04817.84
5.6.100.0090.02717.91
5.6.90.0080.04717.71
5.6.80.0080.02317.48
5.6.70.0080.02617.53
5.6.60.0050.03217.36
5.6.50.0050.03917.42
5.6.40.0020.04717.51
5.6.30.0050.03917.46
5.6.20.0050.03317.34
5.6.10.0080.03817.47
5.6.00.0080.03517.47
5.5.380.0070.03417.31
5.5.370.0050.03917.27
5.5.360.0070.04417.41
5.5.350.0070.02117.45
5.5.340.0080.04817.67
5.5.330.0080.04317.54
5.5.320.0070.03017.60
5.5.310.0070.04217.62
5.5.300.0070.04517.77
5.5.290.0090.02517.80
5.5.280.0050.04817.50
5.5.270.0080.03217.75
5.5.260.0090.02817.71
5.5.250.0140.03017.66
5.5.240.0070.04217.42
5.5.230.0120.02117.22
5.5.220.0120.03817.22
5.5.210.0080.03517.34
5.5.200.0050.04017.40
5.5.190.0020.04817.35
5.5.180.0030.02617.24
5.5.170.0040.01114.19
5.5.160.0060.04317.17
5.5.150.0070.04017.40
5.5.140.0030.03117.42
5.5.130.0050.04117.29
5.5.120.0080.04217.23
5.5.110.0060.04117.15
5.5.100.0070.04317.20
5.5.90.0040.04517.25
5.5.80.0070.02017.18
5.5.70.0080.03917.27
5.5.60.0050.02517.26
5.5.50.0100.03717.03
5.5.40.0150.03717.28
5.5.30.0100.03317.22
5.5.20.0050.03917.30
5.5.10.0120.03517.23
5.5.00.0080.03017.18
5.4.450.0030.02315.19
5.4.440.0050.02615.28
5.4.430.0030.03115.16
5.4.420.0040.04715.43
5.4.410.0070.03415.22
5.4.400.0030.03314.96
5.4.390.0060.02215.13
5.4.380.0070.03515.28
5.4.370.0050.04215.12
5.4.360.0030.03115.02
5.4.350.0050.04015.25
5.4.340.0070.03414.88
5.4.330.0050.00911.21
5.4.320.0050.03215.11
5.4.310.0050.02215.10
5.4.300.0080.03315.25
5.4.290.0080.01814.99
5.4.280.0050.04314.87
5.4.270.0020.02315.09
5.4.260.0050.02515.06
5.4.250.0120.03515.12
5.4.240.0070.03415.20
5.4.230.0060.02314.99
5.4.220.0050.02414.96
5.4.210.0090.03915.03
5.4.200.0030.04314.97
5.4.190.0050.02915.06
5.4.180.0000.05114.96
5.4.170.0030.03315.04
5.4.160.0060.01915.02
5.4.150.0050.04315.01
5.4.140.0080.03613.90
5.4.130.0020.02513.95
5.4.120.0050.03713.87
5.4.110.0070.02013.83
5.4.100.0050.02013.78
5.4.90.0000.02413.73
5.4.80.0080.02113.68
5.4.70.0060.01713.77
5.4.60.0030.02113.77
5.4.50.0100.01613.67
5.4.40.0060.02013.63
5.4.30.0030.02513.77
5.4.20.0020.02513.79
5.4.10.0030.02113.79
5.4.00.0020.02213.51
5.3.290.0100.04312.69
5.3.280.0080.03212.66
5.3.270.0080.02112.69
5.3.260.0050.04312.71
5.3.250.0050.03812.64
5.3.240.0070.03612.71
5.3.230.0020.03912.66
5.3.220.0030.02712.68
5.3.210.0060.03112.61
5.3.200.0050.02212.64
5.3.190.0070.02012.66
5.3.180.0090.01712.62
5.3.170.0040.02012.69
5.3.160.0030.02212.70
5.3.150.0020.02312.63
5.3.140.0080.01812.71
5.3.130.0030.02112.65
5.3.120.0080.01812.65
5.3.110.0070.01612.64
5.3.100.0030.02312.45
5.3.90.0050.02012.41
5.3.80.0060.01612.38
5.3.70.0030.02412.40
5.3.60.0000.02212.35
5.3.50.0050.02112.36
5.3.40.0040.02412.40
5.3.30.0090.01512.34
5.3.20.0030.03612.28
5.3.10.0010.01612.21
5.3.00.0050.01812.23

preferences:
45.83 ms | 401 KiB | 5 Q