3v4l.org

run code in 300+ PHP versions simultaneously
<?php function lzw_compress($string) { // compression $dictionary = array_flip(range("\0", "\xFF")); $word = ""; $codes = array(); for ($i=0; $i <= strlen($string); $i++) { $x = substr($string, $i, 1); if (strlen($x) && isset($dictionary[$word . $x])) { $word .= $x; } elseif ($i) { $codes[] = $dictionary[$word]; $dictionary[$word . $x] = count($dictionary); $word = $x; } } // convert codes to binary string $dictionary_count = 256; $bits = 8; // ceil(log($dictionary_count, 2)) $return = ""; $rest = 0; $rest_length = 0; foreach ($codes as $code) { $rest = ($rest << $bits) + $code; $rest_length += $bits; $dictionary_count++; if ($dictionary_count >> $bits) { $bits++; } while ($rest_length > 7) { $rest_length -= 8; $return .= chr($rest >> $rest_length); $rest &= (1 << $rest_length) - 1; } } return $return . ($rest_length ? chr($rest << (8 - $rest_length)) : ""); } /** LZW decompression * @param string compressed binary data * @return string original data */ function lzw_decompress($binary) { $dictionary_count = 256; $bits = 8; $codes = array(); $rest = 0; $rest_length = 0; mb_internal_encoding("UTF-8"); for ($i = 0; $i < mb_strlen($binary); $i++ ) {$codes[] = mb_ord(mb_substr($binary, $i, 1)); } // decompression $dictionary = range("\0", "\xFF"); $return = ""; foreach ($codes as $i => $code) { $element = $dictionary[$code]; if (!isset($element)) $element = $word . $word[0]; $return .= $element; if ($i) $dictionary[] = $word . $element[0]; $word = $element; } return $return; } function mb_ord($string) { if (extension_loaded('mbstring') === true) { mb_language('Neutral'); mb_internal_encoding('UTF-8'); mb_detect_order(array('UTF-8', 'ISO-8859-15', 'ISO-8859-1', 'ASCII')); $result = unpack('N', mb_convert_encoding($string, 'UCS-4BE', 'UTF-8')); if (is_array($result) === true) return $result[1]; } return ord($string); } echo lzw_compress('');

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.70.0120.00616.63
8.3.60.0110.00318.56
8.3.50.0080.00822.05
8.3.40.0070.01118.72
8.3.30.0030.01219.09
8.3.20.0040.00420.14
8.3.10.0080.00022.00
8.3.00.0030.00622.52
8.2.180.0070.01016.88
8.2.170.0120.00318.82
8.2.160.0100.00322.96
8.2.150.0000.00825.66
8.2.140.0060.00324.66
8.2.130.0040.00426.16
8.2.120.0080.00019.36
8.2.110.0030.00720.92
8.2.100.0110.00017.78
8.2.90.0040.00418.81
8.2.80.0030.00617.97
8.2.70.0040.00417.50
8.2.60.0040.00417.93
8.2.50.0060.00618.10
8.2.40.0000.00818.16
8.2.30.0000.01017.94
8.2.20.0000.00717.62
8.2.10.0050.00319.35
8.2.00.0100.00017.45
8.1.280.0070.01425.92
8.1.270.0060.00322.10
8.1.260.0060.00326.35
8.1.250.0110.00428.09
8.1.240.0040.00722.65
8.1.230.0110.00017.63
8.1.220.0030.00517.74
8.1.210.0060.00318.77
8.1.200.0040.00417.11
8.1.190.0080.00017.10
8.1.180.0050.00318.10
8.1.170.0000.00818.56
8.1.160.0040.00421.93
8.1.150.0040.00418.57
8.1.140.0050.00317.39
8.1.130.0000.00717.82
8.1.120.0030.00317.25
8.1.110.0040.00417.29
8.1.100.0050.00317.32
8.1.90.0000.00717.31
8.1.80.0050.00217.24
8.1.70.0040.00417.30
8.1.60.0030.00517.50
8.1.50.0040.00417.30
8.1.40.0040.00417.36
8.1.30.0030.00617.46
8.1.20.0040.00417.63
8.1.10.0000.00717.41
8.1.00.0040.00417.16
8.0.300.0060.00318.77
8.0.290.0030.00616.58
8.0.280.0050.00318.29
8.0.270.0040.00417.19
8.0.260.0030.00316.78
8.0.250.0030.00316.84
8.0.240.0000.01016.88
8.0.230.0030.00316.91
8.0.220.0060.00016.73
8.0.210.0000.00716.89
8.0.200.0040.00416.91
8.0.190.0000.00816.88
8.0.180.0030.00716.89
8.0.170.0040.00416.78
8.0.160.0050.00216.77
8.0.150.0040.00416.86
8.0.140.0000.00716.81
8.0.130.0060.00013.34
8.0.120.0000.00816.83
8.0.110.0000.00716.77
8.0.100.0000.00816.68
8.0.90.0040.00416.68
8.0.80.0100.01116.90
8.0.70.0070.00016.70
8.0.60.0000.00716.86
8.0.50.0070.00016.82
8.0.30.0100.01316.98
8.0.20.0100.01017.40
8.0.10.0000.01017.00
8.0.00.0090.01216.79
7.4.330.0000.00515.00
7.4.320.0060.00016.38
7.4.300.0000.00616.40
7.4.290.0060.00016.52
7.4.280.0000.00716.45
7.4.270.0030.00316.49
7.4.260.0030.00316.43
7.4.250.0000.00716.46
7.4.240.0040.00416.40
7.4.230.0000.00716.56
7.4.220.0100.00716.34
7.4.210.0090.00616.46
7.4.200.0040.00416.46
7.4.190.0060.00316.38
7.4.160.0060.00916.43
7.4.150.0000.01717.40
7.4.140.0130.00517.86
7.4.130.0090.00916.44
7.4.120.0050.01216.26
7.4.110.0100.00716.55
7.4.100.0100.01316.48
7.4.90.0030.01416.41
7.4.80.0060.01219.39
7.4.70.0080.00816.29
7.4.60.0080.01016.24
7.4.50.0000.00816.46
7.4.40.0030.00822.77
7.4.30.0030.01216.22
7.4.00.0060.00914.98
7.3.330.0000.00513.30
7.3.320.0000.00613.20
7.3.310.0040.00416.14
7.3.300.0000.00716.27
7.3.290.0070.00716.25
7.3.280.0050.01016.30
7.3.270.0030.01317.40
7.3.260.0030.01416.52
7.3.250.0090.01016.46
7.3.240.0100.00716.32
7.3.230.0030.01316.40
7.3.210.0080.01116.31
7.3.200.0030.01319.39
7.3.190.0060.01516.38
7.3.180.0100.00616.33
7.3.170.0110.00616.36
7.3.160.0060.00916.26
7.3.120.0080.01014.75
7.3.110.0030.01514.58
7.3.100.0000.01514.48
7.3.90.0040.01114.80
7.3.80.0070.00714.87
7.3.70.0040.01114.88
7.3.60.0120.00614.67
7.3.50.0150.00414.84
7.3.40.0090.00614.58
7.3.30.0000.00814.42
7.3.20.0110.00416.61
7.3.10.0040.01116.58
7.3.00.0070.01016.50
7.2.330.0080.00816.60
7.2.320.0040.01416.54
7.2.310.0120.00616.48
7.2.300.0160.00316.58
7.2.290.0140.00416.56
7.2.250.0040.01514.67
7.2.240.0070.00714.72
7.2.230.0000.01414.79
7.2.220.0070.01114.67
7.2.210.0090.00615.11
7.2.200.0030.01214.95
7.2.190.0070.01014.59
7.2.180.0030.01014.51
7.2.170.0090.00314.94
7.2.60.0040.01116.90
7.2.00.0030.01019.24
7.1.330.0040.00815.90
7.1.320.0100.00716.01
7.1.310.0000.01515.76
7.1.300.0000.01615.85
7.1.290.0040.00715.93
7.1.280.0100.00315.76
7.1.270.0070.00715.95
7.1.260.0000.01415.79
7.1.200.0070.00415.88
7.1.100.0030.00917.86
7.1.70.0000.00716.86
7.1.60.0140.01119.82
7.1.50.0130.01016.79
7.1.00.0070.07322.45
7.0.200.0040.00416.91
7.0.140.0000.07022.09
7.0.60.0100.08020.00
7.0.50.0030.08317.84
7.0.40.0130.08020.18
7.0.30.0300.07720.12
7.0.20.0230.07020.19
7.0.10.0270.05320.23
7.0.00.0030.04320.20
5.6.280.0000.07721.14
5.6.210.0100.07720.73
5.6.200.0100.04318.27
5.6.190.0130.04020.63
5.6.180.3470.03720.41
5.6.170.0070.05020.55
5.6.160.0030.06720.46
5.6.150.0000.09018.22
5.6.140.0170.06318.30
5.6.130.0100.07318.16
5.6.120.0070.05721.13
5.6.110.0100.08721.07
5.6.100.0130.07721.04
5.6.90.0100.08021.17
5.6.80.0000.04720.52
5.6.70.0270.07020.40
5.5.350.0130.07720.45
5.5.340.0130.04318.09
5.5.330.0030.04320.40
5.5.320.0200.04720.35
5.5.310.0300.06720.27
5.5.300.0000.04018.07
5.5.290.0130.08317.98
5.5.280.0030.08720.91
5.5.270.0170.06020.76
5.5.260.0000.04720.80
5.5.250.0170.05020.62
5.5.240.0070.07720.06
5.4.450.0100.05719.48
5.4.440.0170.07019.58
5.4.430.0130.05019.42
5.4.420.0070.06719.51
5.4.410.0170.07019.41
5.4.400.0800.00018.60
5.4.390.0830.00018.79
5.4.380.0130.06718.82
5.4.370.0230.05318.86
5.4.360.0170.05718.82
5.4.350.0270.04718.65
5.4.340.0100.06018.65
5.4.320.0050.03712.59
5.4.310.0070.04412.59
5.4.300.0100.03112.59
5.4.290.0070.03612.59
5.4.280.0030.04912.48
5.4.270.0170.06319.00
5.4.260.0100.05318.96
5.4.250.0130.07318.96
5.4.240.0130.06718.63
5.4.230.0170.04718.93
5.4.220.0130.05018.79
5.4.210.0070.06319.02
5.4.200.0200.07019.05
5.4.190.0270.03718.91
5.4.180.0070.05318.89
5.4.170.0130.05719.00
5.4.160.0100.06018.79
5.4.150.0100.05718.85
5.4.140.0030.05716.57
5.4.130.0100.05316.47
5.4.120.0170.05716.43
5.4.110.0130.05716.59
5.4.100.0100.06716.55
5.4.90.0200.06716.55
5.4.80.0230.05316.37
5.4.70.0070.05316.64
5.4.60.0070.06716.57
5.4.50.0170.05316.45
5.4.40.0100.06016.54
5.4.30.0070.05316.57
5.4.20.0100.05316.50
5.4.10.0130.06716.58
5.4.00.0200.04715.78
5.3.290.0090.03712.84
5.3.280.0030.06714.75
5.3.270.0070.06314.76
5.3.260.0070.05714.68
5.3.250.0070.07314.53
5.3.240.0070.05714.83
5.3.230.0030.07014.68
5.3.220.0100.05714.73
5.3.210.0100.07014.64
5.3.200.0230.06014.58
5.3.190.0130.04714.83
5.3.180.0030.05314.62
5.3.170.0100.07014.63
5.3.160.0100.06314.83
5.3.150.0130.06314.74
5.3.140.0070.05314.67
5.3.130.0100.08314.86
5.3.120.0100.06014.72
5.3.110.0030.08714.82
5.3.100.0270.05014.21
5.3.90.0030.07714.19
5.3.80.0100.06314.19
5.3.70.0230.04714.08
5.3.60.0170.04714.30
5.3.50.0130.05713.89
5.3.40.0130.06714.11
5.3.30.0100.05013.99
5.3.20.0170.04714.00
5.3.10.0130.04713.92
5.3.00.0070.07713.56
5.2.170.0070.04311.21
5.2.160.0130.04311.20
5.2.150.0100.05711.33
5.2.140.0200.02711.32
5.2.130.0070.04011.02
5.2.120.0100.03711.28
5.2.110.0030.04311.15
5.2.100.0170.02711.19
5.2.90.0100.04011.18
5.2.80.0130.04011.27
5.2.70.0070.04011.09
5.2.60.0100.03711.14
5.2.50.0100.04711.20
5.2.40.0070.04011.09
5.2.30.0070.04011.02
5.2.20.0070.05711.05
5.2.10.0100.04011.04
5.2.00.0000.05010.89
5.1.60.0030.03710.07
5.1.50.0070.04310.16
5.1.40.0070.04710.18
5.1.30.0130.03710.53
5.1.20.0130.03010.55
5.1.10.0000.06010.27
5.1.00.0170.04010.13
5.0.50.0070.0278.73
5.0.40.0070.0278.72
5.0.30.0030.0438.31
5.0.20.0100.0238.38
5.0.10.0070.0338.21
5.0.00.0000.0538.23
4.4.90.0070.0307.22
4.4.80.0000.0307.23
4.4.70.0030.0377.23
4.4.60.0070.0237.23
4.4.50.0130.0207.23
4.4.40.0100.0377.23
4.4.30.0030.0237.23
4.4.20.0030.0337.18
4.4.10.0130.0207.18
4.4.00.0100.0407.18
4.3.110.0000.0277.18
4.3.100.0070.0207.18
4.3.90.0000.0277.18
4.3.80.0070.0307.18
4.3.70.0070.0177.18
4.3.60.0070.0277.18
4.3.50.0030.0207.18
4.3.40.0030.0477.18
4.3.30.0130.0207.18
4.3.20.0100.0137.18
4.3.10.9071.1901189.66
4.3.01.0801.1701167.10

preferences:
48.94 ms | 401 KiB | 5 Q