3v4l.org

run code in 300+ PHP versions simultaneously
<?php function key_values($key) { if ($key[0] == '>') { [$lower, $upper] = [substr($key, 1), 'INF']; } else { [$lower, $upper] = explode('-', $key); } return [$lower, $upper]; } function convert_slabs($slabs) { $bounds = array(); $last_value = reset($slabs); [$lb, $ub] = [$lower, $upper] = key_values(key($slabs)); while ($value = next($slabs)) { [$lower, $upper] = key_values(key($slabs)); // new entry required? if ($value != $last_value) { $bounds[] = (object)['lb' => $lb, 'ub' => $ub, 'value' => $last_value]; [$lb, $ub] = [$lower, $upper]; $last_value = $value; } else { // no, just extend the upper bound $ub = $upper; } } // add the last object $bounds[] = (object)['lb' => $lb, 'ub' => $ub, 'value' => $last_value]; return $bounds; } $slabs_array = array( [ '0-300' => 2.5, '300-500' => 2.5, '500-1000' => 2.5, '1000-5000' => 2.4, '>5000' => 2.4 ], [ '0-300' => 1.2, '300-500' => 1.2, '500-1000' => 1.2, '1000-5000' => 1.3, '>5000' => 1.4 ], [ '0-300' => 2.5, '300-500' => 2.5, '500-1000' => 2.5, '1000-5000' => 2.5, '>5000' => 2.5 ], [ '0-300' => 4.5, '300-500' => 2.5, '500-1000' => 2.5, '1000-5000' => 2.5, '>5000' => 3.5 ], [ '0-300' => 4.5, '300-500' => 3.5, '500-1000' => 3.5, '1000-5000' => 3.5, '>5000' => 3.5 ], [ '0-300' => 1.5, '300-500' => 2.5, '500-1000' => 2.5, '1000-5000' => 2.5, '>5000' => 1.5 ], [ '0-300' => 1.5, '300-500' => 2.5, '500-1000' => 3.5, '1000-5000' => 2.5, '>5000' => 3.5 ], [ '0-300' => 1.5, '300-500' => 2.5, '500-1000' => 2.5, '1000-5000' => 1.5, '>5000' => 1.5 ] ); foreach ($slabs_array as $slabs) { $result = convert_slabs($slabs); echo json_encode($result, JSON_PRETTY_PRINT) . PHP_EOL . PHP_EOL; }

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.5.10.0110.00818.73
8.5.00.0110.01119.70
8.4.160.0110.01025.64
8.4.150.0000.00114.05
8.4.140.0140.01017.45
8.4.130.0090.01217.67
8.4.120.0140.00620.80
8.4.110.0090.00522.70
8.4.100.0050.00517.87
8.4.90.0140.00717.65
8.4.80.0140.00517.66
8.4.70.0160.00617.87
8.4.60.0140.00620.56
8.4.50.0110.00818.73
8.4.40.0030.01717.60
8.4.30.0130.00620.46
8.4.20.0140.00719.87
8.4.10.0090.00023.93
8.3.280.0130.00818.37
8.3.270.0120.00816.47
8.3.260.0150.00516.54
8.3.250.0120.00718.78
8.3.240.0040.00416.69
8.3.230.0090.00816.66
8.3.220.0100.00817.24
8.3.210.0090.01116.75
8.3.200.0040.00316.65
8.3.190.0090.00617.09
8.3.180.0090.00916.86
8.3.170.0000.00816.43
8.3.160.0100.01018.35
8.3.150.0040.01618.91
8.3.140.0030.00618.94
8.3.130.0030.00718.60
8.3.120.0000.01118.83
8.3.110.0110.00020.94
8.3.100.0120.00916.70
8.3.90.0040.00426.77
8.3.80.0000.00916.75
8.3.70.0040.01416.58
8.3.60.0080.00816.50
8.3.50.0080.00819.96
8.3.40.0100.00319.11
8.3.30.0040.01119.18
8.3.20.0070.00024.18
8.3.10.0000.00824.66
8.3.00.0040.00426.16
8.2.290.0070.01220.22
8.2.280.0060.00220.01
8.2.270.0070.00316.81
8.2.260.0110.00716.50
8.2.250.0040.00418.39
8.2.240.0040.00418.85
8.2.230.0050.00322.58
8.2.220.0030.00624.06
8.2.210.0130.00326.77
8.2.200.0070.00418.28
8.2.190.0150.00016.58
8.2.180.0120.00325.92
8.2.170.0170.00319.08
8.2.160.0030.01022.96
8.2.150.0120.00625.66
8.2.140.0040.00424.66
8.2.130.0030.00526.16
8.2.120.0060.00326.16
8.2.110.0130.00922.25
8.2.100.0070.00417.78
8.2.90.0060.00317.90
8.2.80.0040.00418.81
8.2.70.0080.00017.63
8.2.60.0050.00317.89
8.2.50.0040.00418.07
8.2.40.0040.00419.48
8.2.30.0000.00718.04
8.2.20.0000.00720.37
8.2.10.0000.00718.04
8.2.00.0000.00819.39
8.1.330.0090.00816.76
8.1.320.0120.00515.88
8.1.310.0090.00616.05
8.1.300.0130.00318.63
8.1.290.0090.00330.84
8.1.280.0070.00725.92
8.1.270.0070.00023.99
8.1.260.0000.00826.35
8.1.250.0050.00328.09
8.1.240.0040.00423.83
8.1.230.0060.00519.16
8.1.220.0000.00817.74
8.1.210.0050.00318.77
8.1.200.0080.00317.36
8.1.190.0050.00317.25
8.1.180.0040.00418.10
8.1.170.0000.00717.62
8.1.160.0030.00618.89
8.1.150.0050.00318.71
8.1.140.0040.00417.45
8.1.130.0000.00718.89
8.1.120.0030.00617.52
8.1.110.0040.00417.36
8.1.100.0050.00317.50
8.1.90.0050.00217.39
8.1.80.0000.00717.45
8.1.70.0000.00717.39
8.1.60.0040.00817.48
8.1.50.0040.00717.38
8.1.40.0140.00617.40
8.1.30.0090.00917.49
8.1.20.0080.00917.61
8.1.10.0140.00517.36
8.1.00.0110.00817.40
8.0.300.0060.00318.77
8.0.290.0040.00416.75
8.0.280.0000.00818.50
8.0.270.0080.00016.75
8.0.260.0000.00718.45
8.0.250.0000.00716.98
8.0.240.0070.00016.95
8.0.230.0070.00017.00
8.0.220.0000.00716.90
8.0.210.0000.00716.94
8.0.200.0030.00316.86
8.0.190.0090.00616.81
8.0.180.0070.00716.70
8.0.170.0120.00316.80
8.0.160.0070.00316.70
8.0.150.0060.00316.52
8.0.140.0100.00016.75
8.0.130.0130.00316.81
8.0.120.0080.00716.85
8.0.110.0150.00016.82
8.0.100.0130.00316.88
8.0.90.0080.00816.77
8.0.80.0130.00316.70
8.0.70.0060.01016.72
8.0.60.0080.00816.65
8.0.50.0130.00316.73
8.0.30.0150.00016.78
8.0.20.0180.00016.90
8.0.10.0050.01417.01
7.4.330.0000.00515.55
7.4.320.0000.00716.66
7.4.300.0030.00316.49
7.4.290.0060.00716.43
7.4.280.0170.00016.52
7.4.270.0120.00416.46
7.4.260.0120.00216.47
7.4.250.0040.01116.50
7.4.240.0120.00416.42
7.4.230.0110.00716.43
7.4.220.0100.00516.43
7.4.210.0120.00316.48
7.4.200.0090.00616.49
7.4.190.0120.00416.63
7.4.180.0160.00016.61
7.4.160.0080.00816.55
7.4.150.0000.01116.48
7.4.140.0000.00916.39
7.4.130.0030.00616.37
7.4.120.0130.00016.27
7.4.110.0110.00416.31
7.4.100.0120.00616.42
7.4.90.0100.00316.37
7.4.80.0000.01416.38
7.4.70.0150.00016.44
7.4.60.0070.00716.39
7.4.50.0100.00516.29
7.4.40.0000.01516.29
7.4.30.0040.01116.34
7.4.20.0070.00716.23
7.4.10.0130.00016.37
7.4.00.0030.00916.28

preferences:
151.25 ms | 403 KiB | 5 Q