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_decompress(lzw_compress('kornaga'));

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.0090.00922.11
8.3.40.0160.00018.54
8.3.30.0000.01519.09
8.3.20.0030.00520.37
8.3.10.0050.00323.61
8.3.00.0040.00417.80
8.2.180.0150.00616.50
8.2.170.0100.00722.96
8.2.160.0110.00420.11
8.2.150.0000.00824.18
8.2.140.0040.00424.66
8.2.130.0030.00526.16
8.2.120.0080.00020.92
8.2.110.0030.00622.14
8.2.100.0060.00618.09
8.2.90.0000.00818.97
8.2.80.0000.01017.97
8.2.70.0030.00517.50
8.2.60.0050.00317.80
8.2.50.0080.00018.07
8.2.40.0040.00418.16
8.2.30.0000.00918.24
8.2.20.0040.00417.58
8.2.10.0050.00217.99
8.2.00.0000.00819.42
8.1.280.0070.00725.92
8.1.270.0060.01023.83
8.1.260.0040.00426.35
8.1.250.0070.00028.09
8.1.240.0090.00022.02
8.1.230.0110.00019.04
8.1.220.0040.00417.74
8.1.210.0000.00818.77
8.1.200.0070.00317.10
8.1.190.0090.00017.10
8.1.180.0040.00418.10
8.1.170.0040.00418.54
8.1.160.0000.00721.92
8.1.150.0000.00818.87
8.1.140.0040.00417.30
8.1.130.0040.00417.69
8.1.120.0090.00017.31
8.1.110.0070.00017.24
8.1.100.0000.00717.41
8.1.90.0000.01017.34
8.1.80.0040.00417.19
8.1.70.0000.00717.36
8.1.60.0080.00017.47
8.1.50.0040.00417.30
8.1.40.0080.00017.44
8.1.30.0000.00817.58
8.1.20.0040.00417.50
8.1.10.0040.00417.45
8.1.00.0040.00417.34
8.0.300.0070.00018.77
8.0.290.0020.00516.63
8.0.280.0070.00018.25
8.0.270.0040.00417.14
8.0.260.0000.00617.14
8.0.250.0040.00416.93
8.0.240.0030.00316.78
8.0.230.0040.00416.84
8.0.220.0070.00016.75
8.0.210.0070.00016.73
8.0.200.0040.00416.80
8.0.190.0040.00416.91
8.0.180.0070.00016.83
8.0.170.0080.00016.89
8.0.160.0030.00516.74
8.0.150.0050.00316.70
8.0.140.0070.00016.84
8.0.130.0070.00013.24
8.0.120.0030.00616.71
8.0.110.0040.00416.85
8.0.100.0040.00416.84
8.0.90.0050.00316.73
8.0.80.0040.01416.82
8.0.70.0030.00516.85
8.0.60.0090.00016.76
8.0.50.0040.00416.73
8.0.30.0120.00716.94
8.0.20.0050.01417.40
8.0.10.0000.00716.98
8.0.00.0110.00616.59
7.4.330.0050.00015.00
7.4.320.0070.00016.50
7.4.300.0070.00016.54
7.4.290.0030.00316.45
7.4.280.0000.00716.43
7.4.270.0000.00716.50
7.4.260.0030.00316.44
7.4.250.0050.00316.31
7.4.240.0020.00516.41
7.4.230.0030.00316.30
7.4.220.0140.01016.51
7.4.210.0090.00616.59
7.4.200.0000.00716.58
7.4.160.0060.00916.26
7.4.150.0110.00717.40
7.4.140.0120.00917.86
7.4.130.0120.00716.38
7.4.120.0110.00716.53
7.4.110.0090.00916.35
7.4.100.0070.01016.41
7.4.90.0030.01316.14
7.4.80.0120.01319.39
7.4.70.0050.01616.29
7.4.60.0030.01616.40
7.4.50.0000.00416.41
7.4.40.0110.00816.40
7.4.30.0090.00616.29
7.4.00.0040.01414.92
7.3.330.0020.00213.06
7.3.320.0020.00213.12
7.3.310.0000.00716.25
7.3.300.0040.00416.25
7.3.290.0070.01116.25
7.3.280.0110.00816.24
7.3.270.0070.01017.40
7.3.260.0110.00716.25
7.3.250.0090.00916.36
7.3.240.0090.01316.27
7.3.230.0140.00316.45
7.3.210.0100.01016.39
7.3.200.0090.00919.39
7.3.190.0030.01316.32
7.3.180.0060.00916.28
7.3.170.0080.00816.27
7.3.160.0060.01016.22
7.3.120.0060.00614.95
7.3.10.0120.00816.33
7.3.00.0070.01516.15
7.2.330.0070.01716.38
7.2.320.0030.01416.66
7.2.310.0090.01116.48
7.2.300.0060.01016.27
7.2.290.0100.00716.64
7.2.130.0190.00416.33
7.2.120.0130.00916.29
7.2.110.0230.00016.25
7.2.100.0120.01216.10
7.2.90.0160.00316.55
7.2.80.0160.00616.54
7.2.70.0140.00616.34
7.2.60.0070.00816.47
7.2.50.0170.00915.95
7.2.40.0150.00316.34
7.2.30.0150.00016.40
7.2.20.0110.00716.11
7.2.10.0080.00815.97
7.2.00.0080.00817.96
7.1.250.0190.00515.35
7.1.200.0100.00315.77
7.1.100.0000.01118.28
7.1.70.0000.01617.43
7.1.60.0060.00919.70
7.1.50.0070.01717.19
7.1.00.0030.07722.58
7.0.200.0060.00916.88
7.0.140.0070.07322.13
7.0.70.0070.07721.82
7.0.60.0000.08021.69
7.0.50.0100.08022.11
7.0.40.0130.08020.15
7.0.30.0030.09020.02
7.0.20.0070.08020.13
7.0.10.0030.07720.08
7.0.00.0030.06320.07
5.6.280.0100.06721.08
5.6.220.0070.08320.56
5.6.210.0030.08720.70
5.6.200.0070.05721.18
5.6.190.0100.08320.95
5.6.180.0070.08321.15
5.6.170.0030.07721.13
5.6.160.0000.08321.20
5.6.150.0030.08321.15
5.6.140.0000.08321.14
5.6.130.0030.08321.04
5.6.120.0070.06721.14
5.6.110.0030.09321.20
5.6.100.0070.05021.11
5.6.90.0030.08721.09
5.6.80.0030.08020.45
5.6.70.0030.05020.45
5.6.60.0030.08720.42
5.6.50.0200.04320.59
5.6.40.0070.08020.56
5.6.30.0070.08020.33
5.6.20.0030.07320.32
5.6.10.0030.08020.43
5.6.00.0070.09020.39
5.5.360.0130.07020.52
5.5.350.0030.08020.46
5.5.340.0130.07320.93
5.5.330.0200.07320.86
5.5.320.0100.07720.79
5.5.310.0030.07720.91
5.5.300.0000.04320.79
5.5.290.0030.05320.91
5.5.280.0070.06020.91
5.5.270.0070.07320.86
5.5.260.0000.04720.82
5.5.250.0030.06720.67
5.5.240.0070.08020.20
5.5.230.0100.08020.30
5.5.220.0030.07720.21
5.5.210.0000.08020.29
5.5.200.0070.06020.26
5.5.190.0070.07720.22
5.5.180.0030.08020.16
5.5.160.0070.07720.31
5.5.150.0100.07320.27
5.5.140.0070.07720.27
5.5.130.0070.07320.03
5.5.120.0100.08020.21
5.5.110.0000.07720.25
5.5.100.0000.05720.09
5.5.90.0000.07720.15
5.5.80.0100.07720.11
5.5.70.0130.05720.12
5.5.60.0130.06720.13
5.5.50.0030.08320.19
5.5.40.0030.08320.13
5.5.30.0000.05020.09
5.5.20.0100.06720.09
5.5.10.0070.07320.18
5.5.00.0070.07720.11
5.4.450.0000.08719.37
5.4.440.0030.06719.38
5.4.430.0030.08319.36
5.4.420.0030.08019.22
5.4.410.0070.08019.23
5.4.400.0030.07719.04
5.4.390.0070.07018.90
5.4.380.0030.05319.14
5.4.370.0030.07319.13
5.4.360.0030.04719.21
5.4.350.0030.06019.23
5.4.340.0030.05019.13
5.4.320.0130.04318.85
5.4.310.0100.07018.86
5.4.300.0100.06719.16
5.4.290.0000.05018.90
5.4.280.0000.05719.02
5.4.270.0030.06319.05
5.4.260.0000.06019.13
5.4.250.0030.08019.04
5.4.240.0030.07718.94
5.4.230.0170.06718.87
5.4.220.0030.05719.22
5.4.210.0030.04319.04
5.4.200.0100.07019.02
5.4.190.0100.05019.22
5.4.180.0000.04019.12
5.4.170.0030.07019.08
5.4.160.0030.07719.14
5.4.150.0070.07018.86
5.4.140.0100.07016.25
5.4.130.0030.07316.48
5.4.120.0070.07316.47
5.4.110.0170.06316.32
5.4.100.0000.07716.32
5.4.90.0070.07316.54
5.4.80.0100.07016.39
5.4.70.0100.06716.47
5.4.60.0000.06016.54
5.4.50.0070.07016.30
5.4.40.0070.05716.39
5.4.30.0070.04316.49
5.4.20.0000.08016.46
5.4.10.0030.07316.36
5.4.00.0000.06315.99
5.3.290.0030.08014.70
5.3.280.0000.08014.79
5.3.270.0030.06014.80
5.3.260.0030.04714.69
5.3.250.0100.06714.76
5.3.240.0130.06714.67
5.3.230.0000.06714.83
5.3.220.0070.07714.77
5.3.210.0070.07714.77
5.3.200.0070.07714.72
5.3.190.0070.07714.75
5.3.180.0130.07014.69
5.3.170.0100.07014.68
5.3.160.0030.08014.63
5.3.150.0100.06714.66
5.3.140.0070.07014.79
5.3.130.0030.07014.67
5.3.120.0130.06314.70
5.3.110.0030.08014.60
5.3.100.0030.05314.22
5.3.90.0000.08014.08
5.3.80.0000.07014.23
5.3.70.0000.06714.03
5.3.60.0030.07014.19
5.3.50.0000.07713.97
5.3.40.0070.06013.98
5.3.30.0000.08014.09
5.3.20.0000.06713.85
5.3.10.0000.07013.88
5.3.00.0000.08013.76
5.2.170.0000.07011.32
5.2.160.0030.05711.17
5.2.150.0030.06311.25
5.2.140.0000.06011.25
5.2.130.0030.05711.32
5.2.120.0100.04011.09
5.2.110.0030.06711.23
5.2.100.0030.04711.22
5.2.90.0000.06311.21
5.2.80.0030.05711.18
5.2.70.0070.04711.25
5.2.60.0030.06311.22
5.2.50.0030.06711.23
5.2.40.0000.06311.03
5.2.30.0030.06011.12
5.2.20.0030.03711.18
5.2.10.0030.06310.86
5.2.00.0070.05710.95
5.1.60.0030.03710.47
5.1.50.0000.05710.47
5.1.40.0030.05710.47
5.1.30.0030.06010.56
5.1.20.0000.05710.59
5.1.10.0030.05310.47
5.1.00.0030.05310.47
5.0.50.0000.05010.47
5.0.40.0000.03710.47
5.0.30.0000.06710.47
5.0.20.0000.03310.47
5.0.10.0030.03010.47
5.0.00.0030.04710.47
4.4.90.0000.03710.47
4.4.80.0070.02010.47
4.4.70.0000.02010.47
4.4.60.0000.03010.47
4.4.50.0000.02710.47
4.4.40.0000.05710.47
4.4.30.0000.02310.47
4.4.20.0070.03710.47
4.4.10.0000.03710.47
4.4.00.0030.05310.47
4.3.110.0000.02310.47
4.3.100.0000.02310.47
4.3.90.0000.03010.47
4.3.80.0000.05710.47
4.3.70.0000.03310.47
4.3.60.0000.02710.47
4.3.50.0000.04010.47
4.3.40.0000.05310.47
4.3.30.0000.03010.47
4.3.20.0030.02710.47
4.3.10.8271.8003550.89
4.3.00.7601.7903496.45

preferences:
43.33 ms | 401 KiB | 5 Q