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('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.0120.00618.48
8.3.50.0150.00321.92
8.3.40.0090.00918.58
8.3.30.0070.00718.91
8.3.20.0050.00220.29
8.3.10.0040.00422.04
8.3.00.0040.00422.42
8.2.180.0180.00616.88
8.2.170.0110.00422.96
8.2.160.0030.01020.57
8.2.150.0080.00024.18
8.2.140.0090.00024.66
8.2.130.0090.00926.16
8.2.120.0030.00520.81
8.2.110.0080.00022.15
8.2.100.0000.01219.45
8.2.90.0040.00419.11
8.2.80.0000.00817.97
8.2.70.0050.00317.38
8.2.60.0030.00517.91
8.2.50.0030.00518.07
8.2.40.0080.00018.22
8.2.30.0060.00318.04
8.2.20.0000.00817.58
8.2.10.0050.00319.25
8.2.00.0040.00417.57
8.1.280.0140.00725.92
8.1.270.0030.00622.07
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0030.00523.80
8.1.230.0080.00319.01
8.1.220.0040.00417.74
8.1.210.0000.00818.77
8.1.200.0090.00317.23
8.1.190.0000.00917.27
8.1.180.0000.00818.61
8.1.170.0090.00018.57
8.1.160.0040.00422.15
8.1.150.0070.00018.45
8.1.140.0080.00017.25
8.1.130.0040.00417.78
8.1.120.0040.00417.25
8.1.110.0030.00317.32
8.1.100.0050.00217.34
8.1.90.0000.00717.38
8.1.80.0050.00317.30
8.1.70.0040.00417.30
8.1.60.0060.00617.37
8.1.50.0000.00817.42
8.1.40.0080.00017.30
8.1.30.0000.00917.43
8.1.20.0030.00617.49
8.1.10.0040.00417.44
8.1.00.0040.00417.16
8.0.300.0040.00418.77
8.0.290.0070.00017.05
8.0.280.0000.00718.21
8.0.270.0030.00317.18
8.0.260.0040.00416.73
8.0.250.0030.00316.82
8.0.240.0020.00516.89
8.0.230.0030.00316.77
8.0.220.0030.00316.78
8.0.210.0000.00716.84
8.0.200.0030.00316.77
8.0.190.0030.00516.78
8.0.180.0030.00916.77
8.0.170.0040.00416.87
8.0.160.0000.00816.74
8.0.150.0000.00816.66
8.0.140.0080.00016.86
8.0.130.0000.00613.32
8.0.120.0000.00816.86
8.0.110.0070.00016.77
8.0.100.0000.00716.87
8.0.90.0050.00216.75
8.0.80.0090.00616.88
8.0.70.0040.00416.84
8.0.60.0020.00516.68
8.0.50.0070.00016.88
8.0.30.0100.01116.98
8.0.20.0090.01117.40
8.0.10.0080.00016.88
8.0.00.0030.01416.61
7.4.330.0050.00015.00
7.4.320.0060.00016.25
7.4.300.0000.00616.50
7.4.290.0070.00016.48
7.4.280.0000.00816.46
7.4.270.0030.00316.51
7.4.260.0000.00716.37
7.4.250.0050.00316.26
7.4.240.0050.00216.43
7.4.230.0000.00716.33
7.4.220.0110.00616.52
7.4.210.0090.00916.51
7.4.200.0030.00516.59
7.4.190.0040.00416.58
7.4.160.0110.00516.66
7.4.150.0070.01017.40
7.4.140.0100.01017.86
7.4.130.0090.00916.55
7.4.120.0070.01016.38
7.4.110.0140.00316.48
7.4.100.0110.00616.35
7.4.90.0130.00516.34
7.4.80.0110.00719.39
7.4.70.0080.00816.46
7.4.60.0000.01616.49
7.4.50.0040.00416.54
7.4.40.0100.00722.77
7.4.30.0160.00016.54
7.4.00.0050.01214.80
7.3.330.0000.00613.30
7.3.320.0050.00013.34
7.3.310.0040.00416.32
7.3.300.0000.00716.28
7.3.290.0000.01416.29
7.3.280.0090.00716.24
7.3.270.0110.00717.40
7.3.260.0040.01416.57
7.3.250.0110.00616.19
7.3.240.0170.00016.45
7.3.230.0080.01516.39
7.3.210.0030.01716.28
7.3.200.0030.01319.39
7.3.190.0100.01316.49
7.3.180.0090.00616.50
7.3.170.0100.00716.35
7.3.160.0120.00416.38
7.3.120.0060.00814.73
7.3.110.0100.00614.74
7.3.100.0050.01114.69
7.3.90.0050.00914.62
7.3.80.0040.00714.61
7.3.70.0070.00714.53
7.3.60.0070.00814.72
7.3.50.0050.00914.62
7.3.40.0070.01014.68
7.3.30.0100.00814.68
7.3.20.0100.00616.52
7.3.10.0080.00916.52
7.3.00.0060.00716.37
7.2.330.0060.01216.57
7.2.320.0100.00916.50
7.2.310.0070.01016.34
7.2.300.0090.00916.48
7.2.290.0100.00716.61
7.2.250.0160.00014.94
7.2.240.0090.00914.68
7.2.230.0060.00814.96
7.2.220.0050.01014.82
7.2.210.0030.00815.03
7.2.200.0070.00614.94
7.2.190.0100.00314.72
7.2.180.0080.00714.91
7.2.170.0040.01114.94
7.2.160.0040.00714.83
7.2.150.0060.00616.76
7.2.140.0040.01516.59
7.2.130.0000.01416.60
7.2.120.0050.00816.66
7.2.110.0050.01016.72
7.2.100.0060.01016.64
7.2.90.0020.00816.78
7.2.80.0050.00916.60
7.2.70.0100.00716.75
7.2.60.0060.00616.87
7.2.50.0060.00816.66
7.2.40.0060.00616.59
7.2.30.0060.00716.69
7.2.20.0090.00516.64
7.2.10.0070.00716.72
7.2.00.0040.01217.47
7.1.330.0060.00915.70
7.1.320.0080.00515.69
7.1.310.0050.00715.79
7.1.300.0020.01215.72
7.1.290.0050.01215.78
7.1.280.0050.00715.81
7.1.270.0100.00615.76
7.1.260.0020.01015.83
7.1.250.0030.00815.87
7.1.200.0060.00615.62
7.1.100.0040.00817.88
7.1.70.0060.00317.09
7.1.60.0100.01319.82
7.1.50.0090.01517.03
7.1.00.0070.07322.36
7.0.200.0070.00316.82
7.0.140.0030.07321.99
7.0.60.0070.08320.09
7.0.50.0100.04717.95
7.0.40.0030.08719.96
7.0.30.0300.07020.24
7.0.20.0170.04020.12
7.0.10.0200.05020.30
7.0.00.0070.04720.09
5.6.280.0000.07321.17
5.6.210.0100.03720.50
5.6.200.0170.03018.20
5.6.190.0070.06320.55
5.6.180.3930.04020.51
5.6.170.0330.07020.45
5.6.160.0000.04320.43
5.6.150.0030.08318.28
5.6.140.0070.05318.14
5.6.130.0070.07718.19
5.6.120.0000.04321.00
5.6.110.0170.07321.08
5.6.100.0170.07321.15
5.6.90.0070.07321.16
5.6.80.0000.08720.56
5.6.70.0270.08320.42
5.5.350.0100.08320.38
5.5.340.0030.05718.08
5.5.330.0070.04320.37
5.5.320.0300.08020.39
5.5.310.0270.03320.35
5.5.300.0030.05318.02
5.5.290.0070.07318.07
5.5.280.0130.07720.90
5.5.270.0070.07720.93
5.5.260.0200.05020.88
5.5.250.0030.08320.70
5.5.240.0200.02720.07
5.4.450.0100.06019.00
5.4.440.0270.07019.09
5.4.430.0070.05719.56
5.4.420.0170.04719.41
5.4.410.0130.07319.35
5.4.400.0830.00018.93
5.4.390.0900.00018.86
5.4.380.0230.05718.82
5.4.370.0270.05318.65
5.4.360.0200.05318.65
5.4.350.0400.04018.65
5.4.340.0200.05018.63
5.4.320.0060.03612.60
5.4.310.0050.03812.59
5.4.300.0020.04112.59
5.4.290.0080.03512.59
5.4.280.0050.03712.50
5.4.270.0100.06318.75
5.4.260.0170.06018.95
5.4.250.0170.07018.73
5.4.240.0100.06018.94
5.4.230.0170.07719.00
5.4.220.0030.09718.75
5.4.210.0070.05318.99
5.4.200.0230.06018.94
5.4.190.0100.05718.64
5.4.180.0130.04719.09
5.4.170.0130.05318.95
5.4.160.0100.05318.73
5.4.150.0070.06019.00
5.4.140.0030.05316.45
5.4.130.0200.04716.61
5.4.120.0170.04316.50
5.4.110.0070.07316.56
5.4.100.0070.07316.54
5.4.90.0100.06716.61
5.4.80.0070.05016.52
5.4.70.0100.06316.44
5.4.60.0100.06716.38
5.4.50.0170.06316.68
5.4.40.0100.07316.65
5.4.30.0070.07016.53
5.4.20.0130.06316.53
5.4.10.0230.04716.43
5.4.00.0100.05716.08
5.3.290.0080.03912.84
5.3.280.0270.04314.59
5.3.270.0130.07714.90
5.3.260.0070.06714.83
5.3.250.0130.05314.84
5.3.240.0100.06014.71
5.3.230.0030.08014.71
5.3.220.0170.07314.57
5.3.210.0130.05314.66
5.3.200.0070.07014.75
5.3.190.0200.06714.74
5.3.180.0130.05714.51
5.3.170.0030.05714.49
5.3.160.0100.04714.63
5.3.150.0070.07314.73
5.3.140.0130.07314.81
5.3.130.0100.05314.63
5.3.120.0230.06314.61
5.3.110.0130.05014.73
5.3.100.0200.05014.20
5.3.90.0170.06314.20
5.3.80.0070.07013.94
5.3.70.0170.04014.20
5.3.60.0170.06314.08
5.3.50.0130.05314.11
5.3.40.0130.06014.03
5.3.30.0070.06714.00
5.3.20.0300.03713.62
5.3.10.0200.06713.91
5.3.00.0130.04713.91
5.2.170.0200.05011.33
5.2.160.0030.04711.21
5.2.150.0170.03311.25
5.2.140.0100.04311.32
5.2.130.0100.05011.03
5.2.120.0130.04711.10
5.2.110.0030.06011.17
5.2.100.0070.04311.27
5.2.90.0200.03311.15
5.2.80.0100.04011.19
5.2.70.0070.06311.19
5.2.60.0170.04711.23
5.2.50.0100.06311.34
5.2.40.0000.04711.00
5.2.30.0130.03711.14
5.2.20.0170.03311.27
5.2.10.0030.04311.13
5.2.00.0070.03711.03
5.1.60.0100.03710.07
5.1.50.0100.04310.08
5.1.40.0130.04010.24
5.1.30.0100.04310.66
5.1.20.0030.03710.47
5.1.10.0100.04310.24
5.1.00.0100.03010.17
5.0.50.0030.0378.87
5.0.40.0030.0278.48
5.0.30.0030.0438.44
5.0.20.0030.0308.37
5.0.10.0070.0238.26
5.0.00.0030.0508.38
4.4.90.0070.0337.23
4.4.80.0030.0377.23
4.4.70.0000.0307.23
4.4.60.0000.0237.23
4.4.50.0000.0337.23
4.4.40.0030.0407.23
4.4.30.0030.0307.23
4.4.20.0100.0237.23
4.4.10.0030.0307.23
4.4.00.0030.0337.23
4.3.110.0030.0307.23
4.3.100.0000.0237.23
4.3.90.0000.0307.23
4.3.80.0000.0477.23
4.3.70.0070.0277.23
4.3.60.0000.0237.23
4.3.50.0000.0337.23
4.3.40.0030.0407.23
4.3.30.0030.0207.22
4.3.20.0030.0237.22
4.3.11.0171.4071656.74
4.3.01.0301.3001425.43

preferences:
49.49 ms | 401 KiB | 5 Q