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 str_replace('},{', "},\n{", json_encode($result)) . 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.4.120.0070.00524.27
8.4.110.0100.00722.31
8.4.100.0140.00718.04
8.4.90.0120.00920.54
8.4.80.0070.00219.05
8.4.70.0160.00418.83
8.4.60.0170.00618.84
8.4.50.0130.00620.38
8.4.40.0210.00017.46
8.4.30.0130.00720.41
8.4.20.0050.00519.61
8.4.10.0040.00423.85
8.3.250.0070.01018.88
8.3.240.0130.00516.56
8.3.230.0110.00816.93
8.3.220.0100.00718.95
8.3.210.0030.00618.54
8.3.200.0050.00416.36
8.3.190.0130.00317.15
8.3.180.0060.00218.82
8.3.170.0110.00716.67
8.3.160.0090.00617.30
8.3.150.0110.00719.07
8.3.140.0040.00419.07
8.3.130.0080.00316.83
8.3.120.0090.00020.63
8.3.110.0040.00716.50
8.3.100.0040.00424.06
8.3.90.0030.00526.77
8.3.80.0110.00016.38
8.3.70.0060.00916.58
8.3.60.0100.01018.27
8.3.50.0110.00719.85
8.3.40.0040.01119.34
8.3.30.0110.00719.04
8.3.20.0000.00724.18
8.3.10.0040.00424.66
8.3.00.0040.00426.16
8.2.290.0130.00617.05
8.2.280.0100.01018.25
8.2.270.0090.00918.95
8.2.260.0120.00616.58
8.2.250.0040.00416.59
8.2.240.0090.00918.88
8.2.230.0060.00620.94
8.2.220.0030.00637.54
8.2.210.0070.01026.77
8.2.200.0060.00316.88
8.2.190.0040.01116.75
8.2.180.0180.00425.92
8.2.170.0060.01319.09
8.2.160.0100.00322.96
8.2.150.0000.00725.66
8.2.140.0080.00024.66
8.2.130.0000.00826.16
8.2.120.0040.00426.16
8.2.110.0070.00320.57
8.2.100.0060.00617.78
8.2.90.0080.00017.91
8.2.80.0040.00417.97
8.2.70.0000.00817.63
8.2.60.0000.00818.05
8.2.50.0000.00818.07
8.2.40.0040.00420.05
8.2.30.0070.00318.05
8.2.20.0060.00320.46
8.2.10.0000.00718.07
8.2.00.0000.00719.37
8.1.330.0110.00821.87
8.1.320.0110.00817.93
8.1.310.0150.00316.92
8.1.300.0130.00316.40
8.1.290.0090.00030.84
8.1.280.0120.00625.92
8.1.270.0090.00023.99
8.1.260.0000.00726.35
8.1.250.0050.00328.09
8.1.240.0000.00922.59
8.1.230.0070.00420.97
8.1.220.0050.00317.74
8.1.210.0040.00418.95
8.1.200.0060.00617.23
8.1.190.0030.00617.22
8.1.180.0040.00418.10
8.1.170.0050.00318.44
8.1.160.0090.00018.95
8.1.150.0040.00418.64
8.1.140.0040.00417.46
8.1.130.0000.00719.30
8.1.120.0000.01117.49
8.1.110.0050.00217.33
8.1.100.0040.00417.45
8.1.90.0070.00017.47
8.1.80.0050.00317.36
8.1.70.0030.00317.53
8.1.60.0040.00717.59
8.1.50.0090.00317.40
8.1.40.0070.00717.49
8.1.30.0030.00817.61
8.1.20.0110.00417.57
8.1.10.0110.00617.41
8.1.00.0120.00417.44
8.0.300.0040.00420.03
8.0.290.0060.00316.75
8.0.280.0040.00420.16
8.0.270.0000.00717.89
8.0.260.0060.00316.86
8.0.250.0030.00516.91
8.0.240.0000.00816.98
8.0.230.0040.00416.96
8.0.220.0000.00716.88
8.0.210.0030.00316.86
8.0.200.0000.00816.97
8.0.190.0130.00316.88
8.0.180.0120.00416.80
8.0.170.0050.01016.86
8.0.160.0090.00616.82
8.0.150.0120.00416.84
8.0.140.0130.00316.73
8.0.130.0130.00316.71
8.0.120.0130.00316.77
8.0.110.0140.00316.76
8.0.100.0150.00316.74
8.0.90.0160.00016.74
8.0.80.0140.00016.76
8.0.70.0120.00416.71
8.0.60.0080.00816.66
8.0.50.0160.00016.74
8.0.30.0080.00716.83
8.0.20.0130.00316.75
8.0.10.0160.00016.82
7.4.330.0000.00515.55
7.4.320.0030.00316.50
7.4.300.0040.00416.54
7.4.290.0130.00416.50
7.4.280.0130.00516.47
7.4.270.0080.00816.42
7.4.260.0120.00416.52
7.4.250.0120.00316.37
7.4.240.0080.00816.42
7.4.230.0060.01216.37
7.4.220.0130.00316.54
7.4.210.0080.00816.34
7.4.200.0130.00016.45
7.4.190.0100.00516.60
7.4.180.0000.01516.46
7.4.160.0160.00016.40
7.4.150.0170.00016.43
7.4.140.0040.00916.44
7.4.130.0100.00516.23
7.4.120.0120.00416.35
7.4.110.0070.00716.24
7.4.100.0080.00816.45
7.4.90.0120.00316.29
7.4.80.0100.00716.41
7.4.70.0080.00816.35
7.4.60.0110.00416.42
7.4.50.0070.00316.34
7.4.40.0100.00016.28
7.4.30.0080.00316.30
7.4.20.0050.00516.36
7.4.10.0090.00516.26
7.4.00.0080.00216.46

preferences:
106.18 ms | 403 KiB | 5 Q