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; $bias = self::INITIAL_BIAS; $c = count($output) + 1; for ($i = $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); } $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("www.xn---with-SUPER-MONKEYS-pc58ag80a8qai00g7n9n.com");

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.0120.00616.50
8.3.50.0110.00721.92
8.3.40.0080.00818.92
8.3.30.0040.01219.16
8.3.20.0030.00520.21
8.3.10.0090.00022.05
8.3.00.0080.00022.43
8.2.180.0040.01116.50
8.2.170.0090.00622.96
8.2.160.0070.00719.21
8.2.150.0000.00824.18
8.2.140.0000.00824.66
8.2.130.0120.00626.16
8.2.120.0040.00717.93
8.2.110.0060.00321.03
8.2.100.0060.00618.03
8.2.90.0050.00319.52
8.2.80.0090.00017.97
8.2.70.0060.00317.75
8.2.60.0030.00618.05
8.2.50.0040.00418.18
8.2.40.0060.00320.58
8.2.30.0030.00618.24
8.2.20.0000.00917.84
8.2.10.0030.00517.86
8.2.00.0000.00917.97
8.1.280.0180.00025.92
8.1.270.0000.00820.48
8.1.260.0030.00526.35
8.1.250.0030.00628.09
8.1.240.0090.00021.31
8.1.230.0090.00317.58
8.1.220.0050.00317.91
8.1.210.0040.00418.77
8.1.200.0000.00917.35
8.1.190.0090.00017.35
8.1.180.0040.00418.10
8.1.170.0050.00318.71
8.1.160.0040.00422.29
8.1.150.0030.00518.70
8.1.140.0040.00417.61
8.1.130.0060.00617.88
8.1.120.0000.00717.51
8.1.110.0050.00317.54
8.1.100.0030.00517.41
8.1.90.0030.00517.58
8.1.80.0020.00517.62
8.1.70.0040.00417.50
8.1.60.0040.00417.72
8.1.50.0050.00317.58
8.1.40.0040.00417.66
8.1.30.0090.00017.70
8.1.20.0000.00917.68
8.1.10.0000.00817.62
8.1.00.0000.00817.63
8.0.300.0030.00618.77
8.0.290.0040.00416.88
8.0.280.0000.00718.56
8.0.270.0000.00717.38
8.0.260.0030.00316.93
8.0.250.0070.00016.98
8.0.240.0080.00017.15
8.0.230.0050.00317.10
8.0.220.0000.00717.05
8.0.210.0040.00417.05
8.0.200.0070.00017.15
8.0.190.0000.00817.19
8.0.180.0030.00617.11
8.0.170.0040.00417.15
8.0.160.0050.00317.00
8.0.150.0040.00417.00
8.0.140.0030.00617.07
8.0.130.0000.00613.50
8.0.120.0000.00817.05
8.0.110.0050.00217.14
8.0.100.0080.00316.97
8.0.90.0040.00417.04
8.0.80.0060.01017.02
8.0.70.0040.00416.94
8.0.60.0030.00616.91
8.0.50.0040.00416.87
8.0.30.0090.01217.07
8.0.20.0130.00617.46
8.0.10.0050.00317.11
8.0.00.0140.00617.05
7.4.330.0020.00215.00
7.4.320.0030.00316.67
7.4.300.0070.00016.69
7.4.290.0070.00416.69
7.4.280.0030.00316.63
7.4.270.0050.00216.74
7.4.260.0040.00416.53
7.4.250.0050.00316.68
7.4.240.0030.00516.67
7.4.230.0030.00516.51
7.4.220.0110.00916.63
7.4.210.0050.01216.78
7.4.200.0000.00716.61
7.4.190.0040.00416.57
7.4.160.0120.00616.48
7.4.150.0080.01117.40
7.4.140.0140.01217.86
7.4.130.0130.00616.58
7.4.120.0120.00816.57
7.4.110.0090.01016.76
7.4.100.0120.00916.55
7.4.90.0060.01216.64
7.4.80.0080.01519.39
7.4.70.0120.00616.45
7.4.60.0080.01116.64
7.4.50.0000.00916.54
7.4.40.0070.01022.77
7.4.30.0090.00916.44
7.4.10.0100.01015.00
7.4.00.0060.01014.94
7.3.330.0030.00313.57
7.3.320.0070.00013.39
7.3.310.0030.00316.41
7.3.300.0050.00316.60
7.3.290.0160.00316.48
7.3.280.0060.01116.59
7.3.270.0130.01017.40
7.3.260.0100.01016.46
7.3.250.0110.01016.65
7.3.240.0090.00916.53
7.3.230.0090.00916.73
7.3.210.0090.00916.64
7.3.200.0130.00819.39
7.3.190.0110.00716.71
7.3.180.0140.00316.71
7.3.170.0060.00916.58
7.3.160.0030.01516.60
7.3.130.0100.00315.13
7.3.120.0090.00814.90
7.3.110.0090.00814.87
7.3.100.0030.01115.09
7.3.90.0070.00614.79
7.3.80.0070.00615.07
7.3.70.0060.00514.99
7.3.60.0030.01115.04
7.3.50.0050.00914.93
7.3.40.0060.00614.94
7.3.30.0050.00715.04
7.3.20.0080.00516.52
7.3.10.0050.00816.59
7.3.00.0070.00616.84
7.2.330.0110.00716.84
7.2.320.0150.00616.77
7.2.310.0130.01016.86
7.2.300.0130.01016.91
7.2.290.0110.00816.88
7.2.260.0030.01715.13
7.2.250.0130.00715.27
7.2.240.0060.01115.18
7.2.230.0060.01015.24
7.2.220.0060.00815.20
7.2.210.0070.00915.12
7.2.200.0050.01215.19
7.2.190.0060.00615.11
7.2.180.0060.00515.21
7.2.170.0050.00815.06
7.2.160.0090.00615.13
7.2.150.0070.01116.70
7.2.140.0040.00817.05
7.2.130.0090.00617.00
7.2.120.0040.01117.06
7.2.110.0040.01116.85
7.2.100.0030.01017.11
7.2.90.0000.01316.96
7.2.80.0030.00717.06
7.2.70.0030.00717.04
7.2.60.0090.00616.92
7.2.50.0060.00916.84
7.2.40.0080.00416.66
7.2.30.0030.00917.00
7.2.20.0060.00617.10
7.2.10.0110.00316.98
7.2.00.0050.01018.27
7.1.330.0060.00715.85
7.1.320.0060.00615.93
7.1.310.0050.01115.83
7.1.300.0040.01115.87
7.1.290.0020.00915.85
7.1.280.0040.00815.80
7.1.270.0070.00615.70
7.1.260.0070.00615.74
7.1.250.0070.01015.75
7.1.240.0030.01015.60
7.1.230.0040.00815.81
7.1.220.0030.01015.77
7.1.210.0000.01115.82
7.1.200.0080.00615.95
7.1.190.0040.00715.85
7.1.180.0060.00916.00
7.1.170.0100.00315.75
7.1.160.0040.01115.82
7.1.150.0060.00615.88
7.1.140.0030.01015.71
7.1.130.0060.00615.88
7.1.120.0040.00815.92
7.1.110.0150.00015.89
7.1.100.0020.01216.97
7.1.90.0030.00715.96
7.1.80.0060.00615.70
7.1.70.0020.00916.54
7.1.60.0110.00517.80
7.1.50.0090.00516.19
7.1.40.0040.01115.59
7.1.30.0030.00615.83
7.1.20.0100.00315.97
7.1.10.0040.01115.94
7.1.00.0020.02219.00
7.0.330.0060.00615.46
7.0.320.0070.00715.43
7.0.310.0110.00315.46
7.0.300.0060.00315.55
7.0.290.0030.01015.46
7.0.280.0030.00715.46
7.0.270.0110.00315.45
7.0.260.0000.00815.10
7.0.250.0070.00715.33
7.0.240.0080.00815.47
7.0.230.0090.00315.54
7.0.220.0100.00315.29
7.0.210.0060.00915.46
7.0.200.0040.00616.13
7.0.190.0040.00815.29
7.0.180.0030.01415.37
7.0.170.0030.00615.55
7.0.160.0040.01215.42
7.0.150.0070.01015.52
7.0.140.0040.04218.60
7.0.130.0030.01015.34
7.0.120.0060.00615.41
7.0.110.0000.02717.67
7.0.100.0080.01617.65
7.0.90.0040.04417.62
7.0.80.0030.03117.84
7.0.70.0110.03617.86
7.0.60.0080.03717.77
7.0.50.0040.04417.74
7.0.40.0020.04616.69
7.0.30.0050.04116.68
7.0.20.0070.04216.58
7.0.10.0080.03816.66
7.0.00.0030.02416.56
5.6.400.0040.01414.50
5.6.390.0100.00314.51
5.6.380.0070.00714.34
5.6.370.0040.00714.48
5.6.360.0060.00614.50
5.6.350.0060.00614.41
5.6.340.0090.00614.60
5.6.330.0070.01114.56
5.6.320.0100.00714.33
5.6.310.0070.00414.78
5.6.300.0060.01214.89
5.6.290.0040.00514.50
5.6.280.0040.04017.83
5.6.270.0000.01314.45
5.6.260.0050.02017.58
5.6.250.0030.02217.53
5.6.240.0030.02217.64
5.6.230.0090.02817.58
5.6.220.0080.04317.54
5.6.210.0060.03317.56
5.6.200.0030.04417.63
5.6.190.0110.01617.64
5.6.180.0080.02117.64
5.6.170.0030.04817.66
5.6.160.0080.03317.63
5.6.150.0050.03117.62
5.6.140.0080.02717.61
5.6.130.0050.04217.65
5.6.120.0070.04317.53
5.6.110.0070.04417.63
5.6.100.0050.02817.68
5.6.90.0060.02817.61
5.6.80.0050.03817.40
5.6.70.0040.03117.31
5.6.60.0110.02317.32
5.6.50.0050.02617.31
5.6.40.0090.03317.35
5.6.30.0100.02517.15
5.6.20.0050.04717.31
5.6.10.0020.03217.35
5.6.00.0080.02517.06
5.5.380.0030.02216.08
5.5.370.0040.01916.05
5.5.360.0090.01815.90
5.5.350.0070.03016.07
5.5.340.0060.02716.24
5.5.330.0050.03816.30
5.5.320.0050.04316.20
5.5.310.0030.02316.42
5.5.300.0030.02616.15
5.5.290.0130.04216.24
5.5.280.0030.04716.12
5.5.270.0130.03816.21
5.5.260.0070.04216.35
5.5.250.0070.02716.10
5.5.240.0070.04715.96
5.5.230.0100.03515.94
5.5.220.0030.04415.97
5.5.210.0080.03515.92
5.5.200.0030.02515.76
5.5.190.0050.04715.94
5.5.180.0030.04515.79
5.5.170.0030.01014.73
5.5.160.0050.03515.94
5.5.150.0080.02815.88
5.5.140.0100.03516.08
5.5.130.0060.03116.07
5.5.120.0100.03816.16
5.5.110.0050.02715.84
5.5.100.0090.02315.87
5.5.90.0050.02315.67
5.5.80.0060.02815.82
5.5.70.0060.02315.91
5.5.60.0040.02615.77
5.5.50.0070.03815.95
5.5.40.0100.03115.90
5.5.30.0030.02915.92
5.5.20.0090.04215.70
5.5.10.0100.03715.74
5.5.00.0150.01815.86
5.4.450.0110.03915.43
5.4.440.0110.03515.37
5.4.430.0090.02315.53
5.4.420.0070.04115.50
5.4.410.0030.03315.31
5.4.400.0030.02815.34
5.4.390.0090.04015.23
5.4.380.0100.02315.21
5.4.370.0080.03815.39
5.4.360.0020.04615.29
5.4.350.0080.03615.37
5.4.340.0090.03015.21
5.4.330.0030.00711.43
5.4.320.0060.02715.30
5.4.310.0070.03215.22
5.4.300.0020.03115.33
5.4.290.0090.02615.39
5.4.280.0030.04415.23
5.4.270.0090.03415.30
5.4.260.0070.03815.22
5.4.250.0100.03715.38
5.4.240.0080.02315.18
5.4.230.0030.04415.28
5.4.220.0050.04315.38
5.4.210.0120.03215.32
5.4.200.0080.02315.21
5.4.190.0090.04015.23
5.4.180.0100.03915.19
5.4.170.0110.03715.30
5.4.160.0050.03915.25
5.4.150.0130.03015.18
5.4.140.0050.04313.99
5.4.130.0090.03613.89
5.4.120.0050.04014.05
5.4.110.0080.03613.92
5.4.100.0060.01714.03
5.4.90.0060.03213.96
5.4.80.0050.02313.87
5.4.70.0040.04013.97
5.4.60.0060.03813.91
5.4.50.0020.02713.87
5.4.40.0020.02513.86
5.4.30.0070.03413.94
5.4.20.0110.02713.96
5.4.10.0060.02114.00
5.4.00.0080.02113.63
5.3.290.0110.02313.14
5.3.280.0090.02013.04
5.3.270.0050.02213.11
5.3.260.0070.03713.04
5.3.250.0020.04313.05
5.3.240.0030.03813.05
5.3.230.0050.03513.03
5.3.220.0030.04013.03
5.3.210.0060.02113.01
5.3.200.0060.02913.02
5.3.190.0070.03913.05
5.3.180.0050.03413.08
5.3.170.0040.03013.02
5.3.160.0120.03313.08
5.3.150.0050.04013.09
5.3.140.0030.03913.00
5.3.130.0060.02113.05
5.3.120.0100.03713.12
5.3.110.0070.04013.01
5.3.100.0050.03812.79
5.3.90.0100.02812.76
5.3.80.0030.02312.74
5.3.70.0040.02412.75
5.3.60.0050.02412.74
5.3.50.0050.04212.69
5.3.40.0060.03012.74
5.3.30.0030.02312.68
5.3.20.0050.03512.56
5.3.10.0060.02712.57
5.3.00.0040.02912.53

preferences:
47.85 ms | 401 KiB | 5 Q