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--3B-ww4c5e180e575a65lsy2b");

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.01118.68
8.3.50.0050.01421.21
8.3.40.0110.01118.84
8.3.30.0080.00818.96
8.3.20.0060.00318.76
8.3.10.0030.00620.58
8.3.00.0160.00019.43
8.2.180.0140.00416.63
8.2.170.0030.01622.96
8.2.160.0070.01019.08
8.2.150.0040.00424.18
8.2.140.0040.00424.66
8.2.130.0030.00726.16
8.2.120.0040.00419.77
8.2.110.0030.00720.84
8.2.100.0120.00018.16
8.2.90.0050.00319.48
8.2.80.0000.00918.18
8.2.70.0000.00917.75
8.2.60.0060.00318.05
8.2.50.0000.01018.07
8.2.40.0060.00318.28
8.2.30.0030.00518.34
8.2.20.0040.00417.87
8.2.10.0040.00417.95
8.2.00.0040.00417.95
8.1.280.0090.00925.92
8.1.270.0080.00023.99
8.1.260.0080.00026.35
8.1.250.0050.00328.09
8.1.240.0030.00721.02
8.1.230.0000.01721.09
8.1.220.0030.00618.77
8.1.210.0000.00818.86
8.1.200.0100.00017.48
8.1.190.0000.00917.53
8.1.180.0040.00418.10
8.1.170.0060.00318.96
8.1.160.0080.00018.96
8.1.150.0040.00418.79
8.1.140.0040.00417.56
8.1.130.0030.00317.93
8.1.120.0000.00717.45
8.1.110.0030.00517.52
8.1.100.0000.00717.48
8.1.90.0040.00417.60
8.1.80.0040.00417.49
8.1.70.0040.00417.54
8.1.60.0040.00417.58
8.1.50.0040.00717.59
8.1.40.0040.00417.61
8.1.30.0060.00317.72
8.1.20.0040.00417.75
8.1.10.0030.00617.67
8.1.00.0060.00317.50
8.0.300.0070.00320.15
8.0.290.0000.00816.88
8.0.280.0000.00718.49
8.0.270.0040.00417.37
8.0.260.0030.00316.81
8.0.250.0030.00516.94
8.0.240.0000.00817.04
8.0.230.0040.00717.04
8.0.220.0030.00316.91
8.0.210.0000.00716.91
8.0.200.0000.00816.97
8.0.190.0050.00316.99
8.0.180.0080.00016.95
8.0.170.0030.00617.04
8.0.160.0040.00417.09
8.0.150.0000.00816.84
8.0.140.0030.00916.96
8.0.130.0000.00613.45
8.0.120.0040.00416.94
8.0.110.0040.00416.88
8.0.100.0040.00417.02
8.0.90.0000.00717.06
8.0.80.0110.00616.87
8.0.70.0000.00716.95
8.0.60.0040.00417.04
8.0.50.0040.00416.93
8.0.30.0110.00917.23
8.0.20.0120.01017.40
8.0.10.0070.00017.16
8.0.00.0160.00516.87
7.4.330.0000.00513.43
7.4.320.0070.00016.75
7.4.300.0030.00316.54
7.4.290.0000.00716.71
7.4.280.0080.00016.54
7.4.270.0000.00716.52
7.4.260.0060.00313.34
7.4.250.0040.00416.57
7.4.240.0080.00016.51
7.4.230.0040.00416.73
7.4.220.0090.00916.80
7.4.210.0070.00916.68
7.4.200.0070.00016.52
7.4.190.0030.00516.59
7.4.160.0040.01516.76
7.4.150.0150.00317.40
7.4.140.0140.00317.17
7.4.130.0060.01116.50
7.4.120.0110.00616.63
7.4.110.0120.01216.63
7.4.100.0060.01216.49
7.4.90.0190.00016.63
7.4.80.0100.00719.03
7.4.70.0080.00916.65
7.4.60.0030.01416.76
7.4.50.0090.00016.50
7.4.40.0070.00822.27
7.4.30.0040.01916.42
7.4.00.0070.01015.26
7.3.330.0000.00613.48
7.3.320.0050.00013.29
7.3.310.0000.00716.33
7.3.300.0000.00716.39
7.3.290.0070.01416.42
7.3.280.0060.01116.47
7.3.270.0110.00817.40
7.3.260.0150.00818.24
7.3.250.0120.01016.51
7.3.240.0000.01816.55
7.3.230.0100.00716.71
7.3.210.0060.01316.51
7.3.200.0120.01219.39
7.3.190.0130.01016.39
7.3.180.0050.01216.55
7.3.170.0100.00716.73
7.3.160.0130.00316.79
7.3.120.0000.01815.06
7.3.10.0050.00516.90
7.3.00.0060.00316.65
7.2.330.0070.01016.95
7.2.320.0100.00716.60
7.2.310.0120.00616.93
7.2.300.0070.01416.80
7.2.290.0000.01716.79
7.2.130.0060.00916.92
7.2.120.0070.01117.05
7.2.110.0000.01416.88
7.2.100.0030.01017.00
7.2.90.0030.01016.78
7.2.80.0090.00616.87
7.2.70.0080.00517.02
7.2.60.0060.00916.91
7.2.50.0000.01416.93
7.2.40.0030.01017.11
7.2.30.0060.01017.07
7.2.20.0080.00817.01
7.2.10.0040.00816.92
7.2.00.0090.00518.28
7.1.250.0070.00415.54
7.1.200.0120.00015.77
7.1.100.0060.00817.99
7.1.70.0000.00817.09
7.1.60.0110.01119.40
7.1.50.0000.01117.00
7.1.00.0030.05322.40
7.0.200.0000.00716.70
7.0.140.0070.07021.91
7.0.100.0070.07720.00
7.0.90.0270.04720.07
7.0.80.0100.04320.00
7.0.70.0130.06319.92
7.0.60.0130.07720.01
7.0.50.0300.05720.48
7.0.40.0130.08020.10
7.0.30.0130.07720.17
7.0.20.0030.09320.12
7.0.10.0070.08320.09
7.0.00.0100.08020.10
5.6.280.0000.07721.07
5.6.250.0170.07020.50
5.6.240.0130.08020.64
5.6.230.0100.05020.68
5.6.220.0070.08720.68
5.6.210.0170.07320.59
5.6.200.0100.08021.17
5.6.190.0030.08321.16
5.6.180.0070.08021.12
5.6.170.0030.09021.11
5.6.160.0100.05321.19
5.6.150.0100.07721.18
5.6.140.0030.08721.09
5.6.130.0170.07321.11
5.6.120.0100.08321.13
5.6.110.0100.05721.01
5.6.100.0000.09021.07
5.6.90.0070.05321.05
5.6.80.0070.07720.49
5.6.70.0070.08020.37
5.6.60.0070.08020.43
5.6.50.0070.08020.37
5.6.40.0230.06720.45
5.6.30.0030.07720.43
5.6.20.0070.08020.41
5.6.10.0030.07720.34
5.6.00.0030.07020.31
5.5.380.0070.07320.43
5.5.370.0130.06320.36
5.5.360.0130.04320.44
5.5.350.0000.08320.46
5.5.340.0130.08020.95
5.5.330.0130.08020.85
5.5.320.0130.07720.79
5.5.310.0030.09720.94
5.5.300.0100.08720.93
5.5.290.0030.05320.88
5.5.280.0170.04020.97
5.5.270.0000.09020.90
5.5.260.0170.08020.93
5.5.250.0070.07720.66
5.5.240.0070.08020.30
5.5.230.0070.08320.24
5.5.220.0200.05320.31
5.5.210.0130.07320.16
5.5.200.0030.05320.30
5.5.190.0130.07720.16
5.5.180.0070.06720.29
5.5.160.0070.08720.24
5.5.150.0000.08020.25
5.5.140.0070.08020.27
5.5.130.0100.08020.16
5.5.120.0170.06320.25
5.5.110.0070.07720.20
5.5.100.0100.06020.04
5.5.90.0100.04720.20
5.5.80.0100.04320.14
5.5.70.0170.06020.21
5.5.60.0070.04320.16
5.5.50.0030.07720.14
5.5.40.0170.07320.14
5.5.30.0070.08320.20
5.5.20.0130.07020.14
5.5.10.0070.08320.04
5.5.00.0130.07320.15
5.4.450.0070.04019.45
5.4.440.0170.06719.37
5.4.430.0100.07019.42
5.4.420.0100.04319.44
5.4.410.0100.05719.29
5.4.400.0070.08019.25
5.4.390.0100.07718.85
5.4.380.0100.07019.03
5.4.370.0100.07719.18
5.4.360.0100.06718.86
5.4.350.0170.06719.18
5.4.340.0030.07319.20
5.4.320.0030.08319.08
5.4.310.0070.07018.85
5.4.300.0070.08019.03
5.4.290.0070.06718.90
5.4.280.0100.07319.18
5.4.270.0030.05018.90
5.4.260.0070.07019.23
5.4.250.0000.07719.21
5.4.240.0100.07319.02
5.4.230.0030.08319.12
5.4.220.0070.06719.04
5.4.210.0100.07319.06
5.4.200.0100.07019.09
5.4.190.0170.07019.11
5.4.180.0100.07719.20
5.4.170.0100.06318.88
5.4.160.0130.06719.04
5.4.150.0100.06719.01
5.4.140.0100.06016.41
5.4.130.0000.07016.43
5.4.120.0100.06316.39
5.4.110.0030.07016.39
5.4.100.0100.07016.48
5.4.90.0130.06716.49
5.4.80.0070.07316.52
5.4.70.0070.05716.47
5.4.60.0070.07316.50
5.4.50.0070.06016.45
5.4.40.0030.04316.56
5.4.30.0030.06316.50
5.4.20.0070.07016.45
5.4.10.0070.07716.53
5.4.00.0030.08015.87
5.3.290.0030.07314.66
5.3.280.0070.07714.69
5.3.270.0130.05714.70
5.3.260.0130.07314.67
5.3.250.0070.07714.64
5.3.240.0030.05014.59
5.3.230.0030.08014.56
5.3.220.0030.08014.62
5.3.210.0030.05014.59
5.3.200.0000.06314.59
5.3.190.0030.08014.72
5.3.180.0130.07314.65
5.3.170.0030.08014.68
5.3.160.0070.06014.53
5.3.150.0130.03314.63
5.3.140.0100.07014.72
5.3.130.0070.05714.55
5.3.120.0030.06314.57
5.3.110.0100.05314.57
5.3.100.0070.07714.12
5.3.90.0030.08314.14
5.3.80.0070.06014.03
5.3.70.0070.05714.16
5.3.60.0000.07014.14
5.3.50.0070.07714.10
5.3.40.0030.07314.04
5.3.30.0070.06014.05
5.3.20.0070.03713.65
5.3.10.0100.06013.80
5.3.00.0030.07013.59

preferences:
42.67 ms | 401 KiB | 5 Q