3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Punycode { const BASE = 36; const T_MIN = 1; const T_MAX = 26; const SKEW = 38; const DAMP = 700; const INITIAL_BIAS = 72; const INITIAL_N = 128; 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 / self::DAMP : $delta / 2; $delta += $delta / $numPoints; $div = self::BASE - self::T_MIN; $end = ($div * self::T_MAX) / 2; for ($k = 0; $delta > $end; $k += self::BASE) { $delta = (int)($delta / $div); } return $k + (($div + 1) * $delta) / ($delta + self::SKEW); } private function decodeDigit($digits, $index) { if (isset($digits[$index])) { $codePoint = ord($digits[$index]); if ($codePoint >= 0x61 && $codePoint <= 0x7A) { return $codePoint - 97; } else if ($codePoint >= 0x30 && $codePoint <= 0x39) { return $codePoint - 22; } } return false; } private function decodeLabel($input) { if (substr($input, 0, 4) !== 'xn--') { return $input; } $input = substr($input, 4); if (false !== $nonBasicCharsStart = strrpos($input, '-')) { $output = str_split(substr($input, 0, $nonBasicCharsStart), 1); $nonBasicChars = substr($input, $nonBasicCharsStart + 1); } else { $output = []; $nonBasicChars = $input; } $n = self::INITIAL_N; $i = 0; $bias = self::INITIAL_BIAS; for ($j = 0, $l = strlen($nonBasicChars); $j < $l; $i++) { $oldi = $i; $w = 1; for ($k = self::BASE;; $k+= self::BASE) { if (false === $digit = $this->decodeDigit($nonBasicChars, $j++)) { return false; } $i += $digit * $w; if ($k <= $bias) { $t = self::T_MIN; } else if ($k >= $bias + self::T_MAX) { $t = self::T_MAX; } else { $t = $k - $bias; } if ($digit < $t) { break; } $w *= (int) (self::BASE - $t); } $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)]); } 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.0130.00616.75
8.3.50.0090.00721.99
8.3.40.0090.00618.81
8.3.30.0160.00619.13
8.3.20.0080.00020.34
8.3.10.0040.00422.04
8.3.00.0000.00822.45
8.2.180.0000.01518.41
8.2.170.0080.00822.96
8.2.160.0110.00419.46
8.2.150.0080.00024.18
8.2.140.0160.00324.66
8.2.130.0040.00426.16
8.2.120.0070.00317.93
8.2.110.0100.00019.30
8.2.100.0040.01018.09
8.2.90.0000.00919.43
8.2.80.0050.00319.34
8.2.70.0060.00317.62
8.2.60.0000.00818.15
8.2.50.0030.00518.07
8.2.40.0000.00918.47
8.2.30.0000.00818.28
8.2.20.0000.00817.88
8.2.10.0050.00317.83
8.2.00.0000.00817.84
8.1.280.0140.00725.92
8.1.270.0040.00420.15
8.1.260.0000.00726.35
8.1.250.0080.00028.09
8.1.240.0060.00323.80
8.1.230.0090.00321.04
8.1.220.0040.00417.77
8.1.210.0000.00818.77
8.1.200.0070.00317.35
8.1.190.0000.00817.65
8.1.180.0000.00818.65
8.1.170.0080.00018.59
8.1.160.0030.00622.25
8.1.150.0000.00718.75
8.1.140.0040.00417.57
8.1.130.0040.00417.88
8.1.120.0000.00817.48
8.1.110.0040.00417.41
8.1.100.0070.00017.49
8.1.90.0040.00417.46
8.1.80.0040.00417.57
8.1.70.0050.00317.46
8.1.60.0050.00517.69
8.1.50.0030.00617.62
8.1.40.0040.00417.64
8.1.30.0030.00617.76
8.1.20.0040.00417.61
8.1.10.0040.00417.59
8.1.00.0000.00817.66
8.0.300.0050.00318.77
8.0.290.0040.00417.30
8.0.280.0030.00318.58
8.0.270.0000.00817.39
8.0.260.0070.00016.99
8.0.250.0000.00717.10
8.0.240.0040.00417.08
8.0.230.0000.00816.96
8.0.220.0030.00316.96
8.0.210.0040.00417.06
8.0.200.0050.00317.15
8.0.190.0040.00417.20
8.0.180.0020.00517.08
8.0.170.0000.00817.14
8.0.160.0050.00317.14
8.0.150.0040.00417.08
8.0.140.0060.00317.07
8.0.130.0030.00313.52
8.0.120.0050.00316.96
8.0.110.0040.00417.07
8.0.100.0030.00716.97
8.0.90.0040.00416.90
8.0.80.0140.00717.12
8.0.70.0040.00416.85
8.0.60.0050.00316.87
8.0.50.0000.00817.00
8.0.30.0150.00417.22
8.0.20.0100.01317.40
8.0.10.0070.00017.30
8.0.00.0030.01516.87
7.4.330.0020.00215.00
7.4.320.0000.00716.68
7.4.300.0060.00016.61
7.4.290.0090.00316.70
7.4.280.0030.00316.55
7.4.270.0040.00416.57
7.4.260.0000.00716.75
7.4.250.0040.00416.52
7.4.240.0020.00516.61
7.4.230.0050.00316.80
7.4.220.0070.01016.70
7.4.210.0080.00816.75
7.4.200.0040.00416.77
7.4.190.0000.00716.80
7.4.160.0070.01116.71
7.4.150.0040.01417.40
7.4.140.0130.00817.86
7.4.130.0130.00816.59
7.4.120.0140.00316.55
7.4.110.0160.00316.71
7.4.100.0110.01116.44
7.4.90.0040.01416.64
7.4.80.0060.01619.39
7.4.70.0100.00616.59
7.4.60.0100.00916.59
7.4.50.0000.00416.83
7.4.40.0120.00322.77
7.4.30.0070.01016.68
7.4.00.0040.00815.26
7.3.330.0000.00613.38
7.3.320.0020.00513.36
7.3.310.0000.00716.51
7.3.300.0030.00516.57
7.3.290.0140.00716.46
7.3.280.0080.00716.58
7.3.270.0100.00717.40
7.3.260.0000.02216.59
7.3.250.0120.00916.56
7.3.240.0090.00916.69
7.3.230.0110.00716.64
7.3.210.0090.01316.45
7.3.200.0130.01019.39
7.3.190.0170.00216.64
7.3.180.0100.00716.54
7.3.170.0070.01016.63
7.3.160.0100.00716.49
7.3.120.0070.00715.15
7.3.10.0130.00316.65
7.3.00.0060.00916.61
7.2.330.0090.00916.77
7.2.320.0060.01216.59
7.2.310.0080.01116.55
7.2.300.0090.00816.82
7.2.290.0140.00316.71
7.2.130.0120.00316.68
7.2.120.0040.01117.02
7.2.110.0030.01416.77
7.2.100.0100.00016.80
7.2.90.0060.01017.01
7.2.80.0100.00317.01
7.2.70.0030.01316.92
7.2.60.0070.00716.79
7.2.50.0090.00617.07
7.2.40.0040.00916.75
7.2.30.0030.01316.63
7.2.20.0060.00917.03
7.2.10.0090.00616.90
7.2.00.0020.01218.21
7.1.250.0070.00715.85
7.1.100.0040.00718.15
7.1.70.0000.00717.01
7.1.60.0070.01419.82
7.1.50.0030.02016.98
7.1.00.0100.04022.27
7.0.200.0030.00716.76
7.0.140.0000.07722.13
7.0.110.0030.08721.84
7.0.100.0100.06721.71
7.0.90.0000.08721.73
7.0.80.0070.07721.79
7.0.70.0070.07721.66
7.0.60.0030.05021.78
7.0.50.0030.09022.12
7.0.40.0030.07319.99
7.0.30.0030.07020.10
7.0.20.0000.09320.18
7.0.10.0130.08020.18
7.0.00.0070.09020.16
5.6.280.0030.07321.06
5.6.260.0070.04720.70
5.6.250.0100.04320.64
5.6.240.0030.06720.59
5.6.230.0100.07720.59
5.6.220.0000.08320.48
5.6.210.0030.08020.64
5.6.200.0070.08021.01
5.6.190.0070.04721.07
5.6.180.0100.07720.94
5.6.170.0030.08321.10
5.6.160.0030.08321.11
5.6.150.0100.07021.14
5.6.140.0000.06321.00
5.6.130.0070.08021.07
5.6.120.0070.06721.13
5.6.110.0030.05021.10
5.6.100.0030.06321.27
5.6.90.0030.08720.98
5.6.80.0100.07720.54
5.6.70.0130.07020.32
5.6.60.0030.08020.53
5.6.50.0000.05720.43
5.6.40.0100.07720.52
5.6.30.0100.07020.33
5.6.20.0130.06320.48
5.6.10.0030.05020.66
5.6.00.0100.06720.64
5.5.380.0030.05020.31
5.5.370.0000.07720.40
5.5.360.0070.04320.58
5.5.350.0070.07320.46
5.5.340.0070.06720.84
5.5.330.0100.07321.06
5.5.320.0030.07720.93
5.5.310.0100.07321.01
5.5.300.0000.08321.05
5.5.290.0100.04321.01
5.5.280.0100.06720.72
5.5.270.0070.04721.03
5.5.260.0030.07020.91
5.5.250.0030.07720.70
5.5.240.0030.04720.44
5.5.230.0100.07020.43
5.5.220.0030.05020.17
5.5.210.0000.08020.30
5.5.200.0030.07720.33
5.5.190.0030.07720.27
5.5.180.0030.04720.27
5.5.160.0030.06720.24
5.5.150.0070.08020.18
5.5.140.0000.06320.25
5.5.130.0070.07020.40
5.5.120.0030.07020.27
5.5.110.0100.07320.25
5.5.100.0030.08320.19
5.5.90.0000.07020.07
5.5.80.0100.07020.27
5.5.70.0030.08320.26
5.5.60.0000.08019.98
5.5.50.0070.07020.06
5.5.40.0070.07020.03
5.5.30.0030.05320.16
5.5.20.0100.07320.11
5.5.10.0070.08020.18
5.5.00.0100.07320.13
5.4.450.0100.07019.28
5.4.440.0100.07319.28
5.4.430.0000.07719.30
5.4.420.0030.05319.36
5.4.410.0030.07019.44
5.4.400.0000.07319.18
5.4.390.0030.06719.31
5.4.380.0030.04719.23
5.4.370.0070.07319.17
5.4.360.0030.07019.01
5.4.350.0030.07018.96
5.4.340.0000.05019.04
5.4.320.0070.08019.01
5.4.310.0130.06719.00
5.4.300.0030.07319.00
5.4.290.0070.07719.19
5.4.280.0030.07719.22
5.4.270.0030.07319.18
5.4.260.0070.07319.03
5.4.250.0130.07019.08
5.4.240.0030.07319.03
5.4.230.0030.04718.99
5.4.220.0070.07318.98
5.4.210.0100.07319.19
5.4.200.0070.07719.03
5.4.190.0070.05718.98
5.4.180.0070.07319.13
5.4.170.0100.06719.27
5.4.160.0000.07718.99
5.4.150.0000.04018.96
5.4.140.0070.07016.38
5.4.130.0070.06716.34
5.4.120.0030.04316.44
5.4.110.0030.07016.52
5.4.100.0070.06716.60
5.4.90.0030.07016.52
5.4.80.0000.07016.46
5.4.70.0000.06716.54
5.4.60.0030.04716.71
5.4.50.0030.03316.57
5.4.40.0000.03716.53
5.4.30.0030.03316.46
5.4.20.0030.03316.59
5.4.10.0000.03716.51
5.4.00.0070.03015.98
5.3.290.0030.08014.84
5.3.280.0070.06014.63
5.3.270.0070.07314.64
5.3.260.0030.08014.65
5.3.250.0000.06014.67
5.3.240.0030.07714.77
5.3.230.0000.07314.86
5.3.220.0000.07014.73
5.3.210.0030.04014.68
5.3.200.0100.06714.61
5.3.190.0030.06014.46
5.3.180.0000.07714.69
5.3.170.0000.05314.62
5.3.160.0030.04014.59
5.3.150.0030.03314.73
5.3.140.0000.03714.61
5.3.130.0000.03714.60
5.3.120.0000.03714.67
5.3.110.0030.03714.59
5.3.100.0030.04014.04
5.3.90.0000.04014.29
5.3.80.0030.04014.05
5.3.70.0030.03714.05
5.3.60.0000.03714.11
5.3.50.0000.03313.96
5.3.40.0030.03314.01
5.3.30.0030.06314.02
5.3.20.0030.07313.74
5.3.10.0000.03313.84
5.3.00.0100.05013.70

preferences:
45.6 ms | 401 KiB | 5 Q