3v4l.org

run code in 300+ PHP versions simultaneously
<?php function reduce($bits, $prefix, $value = '0') { if (strlen($bits) == 1) { // a single bit can be flipped as needed return array($prefix . ($bits[0] == '0' ? '1' : '0')); } if ($bits[0] == $value) { // nothing to do with this bit, flip the remainder $prefix .= $bits[0]; return reduce(substr($bits, 1), $prefix); } // need to convert balance of string to 1 followed by 0's $prefix .= $bits[0]; $steps = reduce(substr($bits, 1), $prefix, '1'); // now we can flip this bit $prefix = substr($prefix, 0, -1) . ($bits[0] == '0' ? '1' : '0'); $steps[] = $prefix . str_pad('1', strlen($bits) - 1, '0'); // now reduce the new string to 0 $steps = array_merge($steps, reduce(str_pad('1', strlen($bits) - 1, '0'), $prefix)); return $steps; } foreach (array(8, 115) as $i) { $bin = decbin($i); $steps = array_merge(array($bin), reduce($bin, '')); echo "$i ($bin) takes " . (count($steps) - 1) . " steps\n"; print_r($steps); }

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.110.0110.00416.50
8.3.100.0030.01224.06
8.3.90.0040.00426.77
8.3.80.0030.00616.63
8.3.70.0140.00716.63
8.3.60.0120.00318.52
8.3.50.0100.00924.58
8.3.40.0060.00918.97
8.3.30.0150.00018.46
8.3.20.0040.00421.91
8.3.10.0030.00621.91
8.3.00.0040.00423.65
8.2.230.0160.00320.94
8.2.220.0060.00337.54
8.2.210.0070.01126.77
8.2.200.0030.00616.75
8.2.190.0090.00916.63
8.2.180.0040.01125.92
8.2.170.0140.00718.97
8.2.160.0120.00622.96
8.2.150.0080.00025.66
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0000.00920.95
8.2.110.0000.00922.08
8.2.100.0000.01217.85
8.2.90.0080.00018.03
8.2.80.0030.00518.91
8.2.70.0050.00317.63
8.2.60.0050.00317.75
8.2.50.0030.00617.75
8.2.40.0000.00719.52
8.2.30.0060.00319.27
8.2.20.0040.00418.02
8.2.10.0040.00419.32
8.2.00.0000.00719.31
8.1.290.0060.00330.84
8.1.280.0160.00725.92
8.1.270.0040.00424.66
8.1.260.0050.00326.35
8.1.250.0040.00428.09
8.1.240.0000.00923.97
8.1.230.0080.00422.82
8.1.220.0030.00517.78
8.1.210.0080.00018.77
8.1.200.0030.00617.35
8.1.190.0000.00817.23
8.1.180.0050.00318.10
8.1.170.0030.00618.59
8.1.160.0000.00818.99
8.1.150.0020.00519.00
8.1.140.0060.00318.82
8.1.130.0030.00720.04
8.1.120.0040.00417.50
8.1.110.0000.00817.50
8.1.100.0000.00817.52
8.1.90.0100.00017.34
8.1.80.0000.00817.40
8.1.70.0030.00517.36
8.1.60.0090.00017.56
8.1.50.0040.00417.46
8.1.40.0080.00017.57
8.1.30.0030.01217.74
8.1.20.0100.00017.61
8.1.10.0000.00817.63
8.1.00.0070.00317.38
8.0.300.0040.00420.09
8.0.290.0040.00416.58
8.0.280.0000.00718.57
8.0.270.0050.00316.90
8.0.260.0030.00318.41
8.0.250.0030.00516.98
8.0.240.0040.00417.02
8.0.230.0080.00016.98
8.0.220.0030.00316.88
8.0.210.0000.00816.80
8.0.200.0050.00317.01
8.0.190.0000.00816.84
8.0.180.0040.00416.85
8.0.170.0030.00516.80
8.0.160.0050.00216.92
8.0.150.0060.00316.95
8.0.140.0090.00016.83
8.0.130.0000.00613.36
8.0.120.0050.00316.85
8.0.110.0000.00716.79
8.0.100.0030.00416.80
8.0.90.0030.00416.88
8.0.80.0040.00816.79
8.0.70.0040.00416.87
8.0.60.0050.00316.87
8.0.50.0040.00416.90
8.0.30.0080.00716.87
8.0.20.0070.00616.90
8.0.10.0030.00917.01
8.0.00.0080.00916.94
7.4.330.0050.00015.55
7.4.320.0070.00016.53
7.4.300.0000.00616.46
7.4.290.0030.00516.53
7.4.280.0000.00816.63
7.4.270.0070.00016.63
7.4.260.0050.00013.33
7.4.250.0040.00416.48
7.4.240.0030.00416.64
7.4.230.0000.00716.48
7.4.220.0030.00416.67
7.4.210.0050.00716.55
7.4.200.0050.00216.47
7.4.190.0040.00416.54
7.4.180.0080.00016.60
7.4.160.0040.00916.58
7.4.150.0070.00516.46
7.4.140.0050.00716.50
7.4.130.0060.00816.51
7.4.120.0060.00716.52
7.4.110.0080.00516.54
7.4.100.0060.00716.53
7.4.90.0060.00716.53
7.4.80.0050.00817.05
7.4.70.0050.00716.53
7.4.60.0070.00716.49
7.4.50.0070.00616.44
7.4.40.0050.00816.44
7.4.30.0060.00816.43
7.4.20.0060.00716.45
7.4.10.0090.00516.43
7.4.00.0090.00516.57
7.3.330.0050.00216.47
7.3.320.0000.00513.20
7.3.310.0000.00716.40
7.3.300.0060.00216.34
7.3.290.0080.00516.34
7.3.280.0060.00616.37
7.3.270.0060.00416.39
7.3.260.0060.00816.38
7.3.250.0040.00816.34
7.3.240.0070.00916.41
7.3.230.0060.00816.47
7.3.220.0050.00716.33
7.3.210.0060.00916.36
7.3.200.0070.00516.31
7.3.190.0050.00816.35
7.3.180.0060.00616.31
7.3.170.0080.00516.30
7.3.160.0030.01016.29
7.3.150.0060.00816.28
7.3.140.0080.00616.22
7.3.130.0080.00416.31
7.3.120.0100.00516.32
7.3.110.0060.00716.30
7.3.100.0040.00916.24
7.3.90.0050.00916.50
7.3.80.0070.00716.34
7.3.70.0070.00716.38
7.3.60.0050.00716.43
7.3.50.0080.00616.38
7.3.40.0080.00516.39
7.3.30.0070.00816.44
7.3.20.0060.00817.19
7.3.10.0060.00917.10
7.3.00.0070.00717.06
7.2.340.0120.00616.44
7.2.330.0120.00616.43
7.2.320.0120.00716.51
7.2.310.0090.00916.52
7.2.300.0120.00616.46
7.2.290.0090.00916.43
7.2.280.0110.00816.51
7.2.270.0120.00616.44
7.2.260.0110.00716.50
7.2.250.0110.01016.45
7.2.240.0090.01116.48
7.2.230.0120.00616.47
7.2.220.0100.00816.46
7.2.210.0110.00916.48
7.2.200.0140.00616.59
7.2.190.0080.01116.59
7.2.180.0140.00616.46
7.2.170.0130.00816.68
7.2.160.0120.00616.54
7.2.150.0100.00917.40
7.2.140.0150.00517.38
7.2.130.0110.00917.49
7.2.120.0130.00717.41
7.2.110.0130.00717.40
7.2.100.0120.00717.45
7.2.90.0170.00417.46
7.2.80.0130.00717.33
7.2.70.0150.00517.39
7.2.60.0110.00817.29
7.2.50.0100.00817.37
7.2.40.0140.00717.33
7.2.30.0100.00817.35
7.2.20.0190.00917.36
7.2.10.0140.00717.37
7.2.00.0110.01017.41

preferences:
48.56 ms | 403 KiB | 5 Q