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); } lzw_decompress(lzw_compress('function kw($n){return $n*$n} echo kw(5);'));

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.00918.43
8.3.50.0070.01121.99
8.3.40.0150.00018.69
8.3.30.0070.00718.92
8.3.20.0000.00720.30
8.3.10.0080.00022.13
8.3.00.0040.00422.58
8.2.180.0150.00016.75
8.2.170.0090.00622.96
8.2.160.0040.01219.09
8.2.150.0050.00324.18
8.2.140.0050.00324.66
8.2.130.0040.00426.16
8.2.120.0040.00417.63
8.2.110.0060.00322.11
8.2.100.0070.00417.59
8.2.90.0080.00018.80
8.2.80.0040.00417.97
8.2.70.0050.00817.38
8.2.60.0080.00017.91
8.2.50.0060.00318.07
8.2.40.0030.00518.03
8.2.30.0040.00417.82
8.2.20.0000.00717.64
8.2.10.0040.00419.27
8.2.00.0040.00417.54
8.1.280.0140.01025.92
8.1.270.0040.00422.23
8.1.260.0050.00526.35
8.1.250.0080.00028.09
8.1.240.0060.00323.78
8.1.230.0120.00019.17
8.1.220.0080.00017.74
8.1.210.0050.00318.77
8.1.200.0040.00717.10
8.1.190.0080.00017.27
8.1.180.0040.00418.10
8.1.170.0040.00418.59
8.1.160.0000.01022.03
8.1.150.0040.00418.41
8.1.140.0080.00017.34
8.1.130.0000.00717.70
8.1.120.0030.00317.40
8.1.110.0030.00617.26
8.1.100.0050.00217.26
8.1.90.0000.00717.32
8.1.80.0030.00317.38
8.1.70.0030.00317.18
8.1.60.0000.00817.36
8.1.50.0030.00617.39
8.1.40.0000.00717.41
8.1.30.0000.00717.56
8.1.20.0040.00417.55
8.1.10.0060.00317.30
8.1.00.0040.00417.31
8.0.300.0060.00318.77
8.0.290.0070.00016.92
8.0.280.0080.00018.40
8.0.270.0030.00317.06
8.0.260.0060.00016.70
8.0.250.0000.00916.91
8.0.240.0000.00716.85
8.0.230.0000.00716.89
8.0.220.0040.00416.84
8.0.210.0000.00716.86
8.0.200.0030.00316.92
8.0.190.0040.00416.97
8.0.180.0030.00516.86
8.0.170.0040.00416.84
8.0.160.0070.00016.72
8.0.150.0000.00716.79
8.0.140.0000.00716.68
8.0.130.0030.00313.34
8.0.120.0030.00516.79
8.0.110.0050.00216.78
8.0.100.0040.00416.90
8.0.90.0040.00416.73
8.0.80.0160.00016.84
8.0.70.0080.00016.67
8.0.60.0040.00416.73
8.0.50.0040.00416.70
8.0.30.0100.01317.07
8.0.20.0110.01017.40
8.0.10.0030.00517.09
8.0.00.0130.01016.63
7.4.330.0000.00515.00
7.4.320.0030.00316.50
7.4.300.0030.00316.35
7.4.290.0040.00416.49
7.4.280.0050.00316.40
7.4.270.0030.00316.26
7.4.260.0070.00016.49
7.4.250.0000.00716.52
7.4.240.0020.00516.45
7.4.230.0040.00416.26
7.4.220.0120.00616.43
7.4.210.0110.00616.50
7.4.200.0000.00716.50
7.4.190.0000.00716.67
7.4.160.0080.00816.42
7.4.150.0100.00717.40
7.4.140.0100.01017.86
7.4.130.0050.01316.40
7.4.120.0100.01116.43
7.4.110.0140.00616.10
7.4.100.0030.01416.36
7.4.90.0140.00916.38
7.4.80.0150.00919.39
7.4.70.0070.01016.47
7.4.60.0030.01416.32
7.4.50.0050.00316.39
7.4.40.0030.01222.77
7.4.30.0070.01416.57
7.4.00.0030.01214.72
7.3.330.0000.00513.11
7.3.320.0050.00013.35
7.3.310.0070.00016.22
7.3.300.0070.00016.26
7.3.290.0090.00616.25
7.3.280.0070.01216.25
7.3.270.0150.00817.40
7.3.260.0090.00916.40
7.3.250.0110.00616.38
7.3.240.0130.00316.44
7.3.230.0090.01216.51
7.3.210.0090.00816.51
7.3.200.0030.01319.39
7.3.190.0120.00916.41
7.3.180.0080.00816.49
7.3.170.0060.01016.27
7.3.160.0060.01216.27
7.3.120.0040.01314.80
7.3.110.0050.01114.77
7.3.100.0040.01314.88
7.3.90.0100.00014.78
7.3.80.0060.00514.89
7.3.70.0070.00414.57
7.3.60.0070.00614.69
7.3.50.0050.00714.49
7.3.40.0030.00914.70
7.3.30.0070.00414.81
7.3.20.0050.01016.51
7.3.10.0020.01316.67
7.3.00.0080.00616.34
7.2.330.0090.00916.51
7.2.320.0060.01516.32
7.2.310.0130.00316.46
7.2.300.0060.01016.62
7.2.290.0190.00616.59
7.2.250.0120.00514.78
7.2.240.0070.01014.78
7.2.230.0050.01114.99
7.2.220.0080.00714.91
7.2.210.0090.00515.02
7.2.200.0020.00814.65
7.2.190.0100.00314.80
7.2.180.0030.00814.83
7.2.170.0060.00614.95
7.2.160.0030.00714.88
7.2.150.0040.01416.67
7.2.140.0060.00916.84
7.2.130.0060.00916.50
7.2.120.0100.01016.71
7.2.110.0060.00916.60
7.2.100.0030.00916.62
7.2.90.0060.00916.75
7.2.80.0070.01016.87
7.2.70.0130.00616.77
7.2.60.0030.01116.66
7.2.50.0090.00616.86
7.2.40.0070.00716.86
7.2.30.0120.00616.60
7.2.20.0030.01216.77
7.2.10.0110.00416.54
7.2.00.0060.01118.08
7.1.330.0020.01415.87
7.1.320.0040.00915.88
7.1.310.0050.00816.00
7.1.300.0070.00716.12
7.1.290.0030.00815.62
7.1.280.0020.01115.60
7.1.270.0050.00815.73
7.1.260.0040.00815.91
7.1.250.0030.00716.06
7.1.240.0040.01516.01
7.1.230.0040.00716.04
7.1.220.0060.00915.91
7.1.210.0030.01015.68
7.1.200.0050.01015.88
7.1.190.0070.00715.89
7.1.180.0060.00315.67
7.1.170.0060.00916.08
7.1.160.0030.01015.80
7.1.150.0000.01516.09
7.1.140.0030.01015.94
7.1.130.0060.00915.76
7.1.120.0030.01316.04
7.1.110.0060.01616.14
7.1.100.0050.01017.17
7.1.90.0070.01115.81
7.1.80.0000.00915.87
7.1.70.0040.00816.52
7.1.60.0100.01317.87
7.1.50.0100.00916.40
7.1.40.0120.00315.76
7.1.30.0060.00916.02
7.1.20.0110.00316.04
7.1.10.0060.01116.02
7.1.00.0060.04119.14
7.0.330.0040.00815.70
7.0.320.0030.00615.72
7.0.310.0070.00715.32
7.0.300.0070.00715.67
7.0.290.0030.00915.25
7.0.280.0030.01015.47
7.0.270.0060.01015.54
7.0.260.0030.00915.29
7.0.250.0000.01515.53
7.0.240.0100.00715.67
7.0.230.0030.01415.77
7.0.220.0040.00815.67
7.0.210.0040.00815.55
7.0.200.0050.00816.17
7.0.190.0060.00615.64
7.0.180.0000.01415.61
7.0.170.0030.00615.60
7.0.160.0060.01015.65
7.0.150.0110.00315.56
7.0.140.0050.04118.87
7.0.130.0090.00615.70
7.0.120.0060.00915.36
7.0.110.0070.01015.57
7.0.100.0070.00415.55
7.0.90.0000.01115.57
7.0.80.0030.01215.71
7.0.70.0030.00615.51
7.0.60.0150.04417.85
7.0.50.0060.04616.78
7.0.40.0050.03516.94
7.0.30.0280.02216.75
7.0.20.0180.04716.75
7.0.10.0120.04516.91
7.0.00.0080.03116.90
5.6.400.0060.00614.57
5.6.390.0120.00314.81
5.6.380.0000.01214.84
5.6.370.0030.00914.63
5.6.360.0070.01014.55
5.6.350.0080.00414.59
5.6.340.0030.01114.60
5.6.330.0040.01214.41
5.6.320.0140.00714.86
5.6.310.0040.01514.80
5.6.300.0090.00614.80
5.6.290.0000.01414.34
5.6.280.0060.03917.87
5.6.270.0090.00614.97
5.6.260.0030.00914.45
5.6.250.0060.00614.94
5.6.240.0070.00314.39
5.6.230.0070.00714.93
5.6.220.0090.00014.44
5.6.210.0080.04317.54
5.6.200.0060.03316.40
5.6.190.0050.04717.79
5.6.180.0220.02517.38
5.6.170.0140.02117.71
5.6.160.0070.04416.32
5.6.150.0100.03716.40
5.6.140.0100.03316.37
5.6.130.0110.04316.35
5.6.120.0080.04617.78
5.6.110.0120.04717.95
5.6.100.0080.04317.86
5.6.90.0050.02717.72
5.6.80.0080.02017.53
5.6.70.0070.00314.46
5.6.60.0100.00314.25
5.6.50.0140.00714.61
5.6.40.0060.00314.59
5.6.30.0070.00714.23
5.6.20.0130.00314.70
5.6.10.0090.00314.43
5.6.00.0060.00314.55
5.5.380.0090.00614.51
5.5.370.0030.01314.58
5.5.360.0030.00714.80
5.5.350.0090.02617.66
5.5.340.0080.04516.36
5.5.330.0080.03617.41
5.5.320.1670.02317.47
5.5.310.0180.04217.42
5.5.300.0070.03916.36
5.5.290.0080.04116.13
5.5.280.0030.03417.83
5.5.270.0080.04817.73
5.5.260.0040.03517.47
5.5.250.0060.02517.71
5.5.240.0130.04017.44
5.5.230.0030.00914.44
5.5.220.0040.01114.53
5.5.210.0040.00814.66
5.5.200.0040.00714.56
5.5.190.0000.01314.31
5.5.180.0000.00914.26
5.5.170.0000.01014.44
5.5.160.0090.00614.70
5.5.150.0000.01314.46
5.5.140.0070.00714.59
5.5.130.0130.00314.32
5.5.120.0030.00914.74
5.5.110.0110.00014.41
5.5.100.0000.01114.57
5.5.90.0070.00714.46
5.5.80.0100.00714.63
5.5.70.0060.00914.77
5.5.60.0080.00314.55
5.5.50.0040.01414.70
5.5.40.0000.01514.46
5.5.30.0040.01514.42
5.5.20.0080.00414.38
5.5.10.0000.01314.53
5.5.00.0030.00914.24
5.4.450.0050.04716.22
5.4.440.0050.04616.29
5.4.430.0080.04216.30
5.4.420.0020.04616.21
5.4.410.0070.04016.27
5.4.400.0080.02816.17
5.4.390.0100.03716.05
5.4.380.0070.03816.07
5.4.370.0100.03716.11
5.4.360.0050.02816.10
5.4.350.0130.02816.05
5.4.340.0130.03616.03
5.4.330.0030.01013.13
5.4.320.0100.03316.07
5.4.310.0090.03915.99
5.4.300.0070.03016.18
5.4.290.0180.03116.16
5.4.280.0050.04216.00
5.4.270.0090.03715.99
5.4.260.0070.03816.12
5.4.250.0060.02616.13
5.4.240.0050.02516.16
5.4.230.0070.02616.14
5.4.220.0070.03716.06
5.4.210.0110.03516.18
5.4.200.0050.04516.13
5.4.190.0070.03916.18
5.4.180.0030.04616.16
5.4.170.0020.04716.03
5.4.160.0080.03916.14
5.4.150.0050.02816.17
5.4.140.0050.04014.80
5.4.130.0070.03214.72
5.4.120.0050.04214.76
5.4.110.0070.01714.80
5.4.100.0000.02514.86
5.4.90.0090.02414.80
5.4.80.0030.02414.82
5.4.70.0080.03314.73
5.4.60.0020.03414.81
5.4.50.0030.04214.77
5.4.40.0080.03814.91
5.4.30.0030.02914.76
5.4.20.0070.03714.82
5.4.10.0050.02714.71
5.4.00.0030.02114.51
5.3.290.0030.05314.82
5.3.280.0030.04314.84
5.3.270.0130.04014.85
5.3.260.0030.05314.74
5.3.250.0030.04014.73
5.3.240.0000.06714.63
5.3.230.0030.05314.71
5.3.220.0070.05014.67
5.3.210.0070.04014.55
5.3.200.0070.03314.59
5.3.190.0100.08014.68
5.3.180.0130.03314.69
5.3.170.0070.03714.72
5.3.160.0000.05714.70
5.3.150.0000.04314.69
5.3.140.0070.05714.75
5.3.130.0170.03314.80
5.3.120.0130.07014.81
5.3.110.0100.06714.72
5.3.100.0100.07314.20
5.3.90.0070.07314.18
5.3.80.0030.04314.11
5.3.70.0130.06014.17
5.3.60.0070.06014.05
5.3.50.0100.04714.08
5.3.40.0070.04314.09
5.3.30.0070.05314.17
5.3.20.0070.07013.84
5.3.10.0000.05013.77
5.3.00.0000.04713.70
5.2.170.0070.06311.23
5.2.160.0070.05011.30
5.2.150.0030.03011.29
5.2.140.0170.06011.20
5.2.130.0070.03311.16
5.2.120.0070.03711.36
5.2.110.0030.05711.24
5.2.100.0070.03711.25
5.2.90.0100.05711.18
5.2.80.0000.04311.27
5.2.70.0030.06311.25
5.2.60.0070.03711.08
5.2.50.0070.02711.03
5.2.40.0100.05711.07
5.2.30.0000.03311.08
5.2.20.0070.03011.05
5.2.10.0070.05011.11
5.2.00.0030.03710.81
5.1.60.0070.05310.16
5.1.50.0000.06010.25
5.1.40.0070.05310.16
5.1.30.0000.05710.46
5.1.20.0000.05010.45
5.1.10.0000.06010.17
5.1.00.0070.05310.10
5.0.50.0030.0338.84
5.0.40.0100.0338.51
5.0.30.0030.0638.33
5.0.20.0030.0408.37
5.0.10.0070.0438.26
5.0.00.0070.0638.20
4.4.90.0000.0237.54
4.4.80.0000.0407.54
4.4.70.0000.0207.54
4.4.60.0030.0307.54
4.4.50.0100.0337.54
4.4.40.0030.0277.54
4.4.30.0030.0277.54
4.4.20.0070.0407.54
4.4.10.0000.0407.54
4.4.00.0070.0537.54
4.3.110.0030.0337.54
4.3.100.0030.0207.54
4.3.90.0070.0307.54
4.3.80.0030.0537.54
4.3.70.0030.0277.54
4.3.60.0000.0407.54
4.3.50.0030.0237.54
4.3.40.0070.0507.54
4.3.30.0030.0237.54
4.3.20.0030.0407.54
4.3.10.8801.3931237.75
4.3.01.0171.2301132.63

preferences:
56.38 ms | 401 KiB | 5 Q