3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( 1, 2, 3 ); $maxRetries = 5; class RetryIterator { protected static $_currentRetries = 0; public static function iterate($element) { var_dump($element); var_dump(func_get_args()); if ($element == 2) { throw new Exception('Something went wrong'); } } public static function handleException($e, $array) { var_dump(func_get_args()); var_dump('Exception handled'); } public static function retry(&$array, $maxRetries, $iterateCallback, $handleCallback, $iterateParams = null, $handleParams = null, $iterateCallbackObject = null, $handleCallbackObject = null) { while (!empty($array)) { reset($array); $key = key($array); try { if (!is_object($iterateCallbackObject)) { if (is_array($iterateParams) && !empty($iterateParams)) { array_unshift($handleParams, $array[$key]); call_user_func_array($iterateCallback, $iterateParams); } else { call_user_func($iterateCallback, ($array[$key])); } } else { if (is_array($iterateParams) && !empty($iterateParams)) { array_unshift($handleParams, $array[$key]); call_user_func_array(array($iterateCallbackObject, $iterateCallback), $iterateParams); } else { $iterateCallbackObject->$iterateCallback($array[$key]); } } unset($array[$key]); } catch (Exception $e) { static::$_currentRetries++; if (static::$_currentRetries <= $maxRetries) { if (!is_object($handleCallbackObject)) { if (is_array($handleParams) && !empty($handleParams)) { array_unshift($handleParams, $e, $array); call_user_func_array($handleCallback, $handleParams); } else { call_user_func($handleCallback, $e, $array); } } else { if (is_array($handleParams) && !empty($handleParams)) { array_unshift($handleParams, $e, $array); call_user_func_array(array($handleCallbackObject, $handleCallback), $handleParams); } else { $handleCallbackObject->$handleCallback($e, $array); } } } else { throw new Exception('maxRetries reached'); } } } } } class Foo { public function bar($el, $a = null, $b = null, $c = null) { var_dump(func_get_args()); var_dump($el); if ($el == 2) { throw new Exception('Exception'); } } public function handle($e, $arr, $a = null, $b = null, $c = null) { var_dump(func_get_args()); var_dump('Exception handled'); } } try { RetryIterator::retry($arr, 5, 'RetryIterator::iterate', 'RetryIterator::handleException'); } catch (Exception $e) { } $arr = array(1, false, 2, 3); $foo = new Foo(); try { RetryIterator::retry($arr, 5, 'bar', 'handle', null, null, $foo, $foo); } catch (Exception $e) { } $arr = array(1, false, 2, 3); $foo = new Foo(); RetryIterator::retry($arr, 5, 'bar', 'handle', array(1, 2, 3), array(1, 2, 3), $foo, $foo);

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.0090.01218.43
8.3.50.0190.00421.97
8.3.40.0110.00718.92
8.3.30.0070.01019.13
8.3.20.0000.00920.39
8.3.10.0080.00022.09
8.3.00.0060.00322.27
8.2.180.0100.00716.88
8.2.170.0030.01322.96
8.2.160.0090.00620.94
8.2.150.0000.00924.18
8.2.140.0060.00324.66
8.2.130.0060.00326.16
8.2.120.0030.01017.63
8.2.110.0090.00022.12
8.2.100.0100.00318.03
8.2.90.0030.00519.26
8.2.80.0040.00417.97
8.2.70.0060.00317.50
8.2.60.0000.00918.05
8.2.50.0060.00318.07
8.2.40.0090.00018.34
8.2.30.0030.00518.29
8.2.20.0000.00817.83
8.2.10.0060.00317.94
8.2.00.0050.00317.85
8.1.280.0060.01525.92
8.1.270.0030.00622.23
8.1.260.0030.00626.35
8.1.250.0030.00628.09
8.1.240.0070.00423.89
8.1.230.0100.00319.18
8.1.220.0000.00817.74
8.1.210.0000.00818.77
8.1.200.0040.00717.23
8.1.190.0030.00517.36
8.1.180.0080.00018.75
8.1.170.0000.00818.57
8.1.160.0090.00021.98
8.1.150.0000.00818.70
8.1.140.0040.00417.46
8.1.130.0040.00417.82
8.1.120.0050.00217.54
8.1.110.0040.00417.43
8.1.100.0040.00417.52
8.1.90.0030.00617.48
8.1.80.0040.00417.48
8.1.70.0040.00417.37
8.1.60.0090.00317.61
8.1.50.0030.00617.53
8.1.40.0000.00817.57
8.1.30.0060.00317.58
8.1.20.0000.00817.68
8.1.10.0000.00817.53
8.1.00.0030.00617.45
8.0.300.0040.00418.77
8.0.290.0080.00017.04
8.0.280.0000.00818.40
8.0.270.0050.00417.30
8.0.260.0070.00016.98
8.0.250.0070.00017.05
8.0.240.0000.00717.09
8.0.230.0050.00317.02
8.0.220.0070.00017.01
8.0.210.0000.00817.02
8.0.200.0000.00716.93
8.0.190.0040.00416.95
8.0.180.0080.00016.96
8.0.170.0080.00017.03
8.0.160.0000.00916.97
8.0.150.0080.00017.05
8.0.140.0030.00616.88
8.0.130.0040.00413.43
8.0.120.0030.00616.89
8.0.110.0040.00416.95
8.0.100.0040.00416.83
8.0.90.0030.00516.96
8.0.80.0150.00317.00
8.0.70.0040.00416.96
8.0.60.0030.00617.05
8.0.50.0060.00317.04
8.0.30.0170.00817.20
8.0.20.0150.01117.40
8.0.10.0080.00017.02
8.0.00.0100.01316.97
7.4.330.0000.00515.00
7.4.320.0030.00316.66
7.4.300.0070.00016.57
7.4.290.0100.00016.50
7.4.280.0070.00416.53
7.4.270.0040.00416.69
7.4.260.0000.00816.40
7.4.250.0040.00416.48
7.4.240.0020.00816.59
7.4.230.0000.00816.63
7.4.220.0120.00916.66
7.4.210.0110.00516.58
7.4.200.0050.00216.47
7.4.190.0000.00816.73
7.4.160.0120.00816.44
7.4.150.0130.00917.40
7.4.140.0120.01317.86
7.4.130.0140.01016.66
7.4.120.0090.01216.51
7.4.110.0070.01316.61
7.4.100.0180.00316.54
7.4.90.0170.00616.36
7.4.80.0170.00419.39
7.4.70.0180.00616.55
7.4.60.0160.00316.70
7.4.50.0000.00916.85
7.4.40.0090.00922.77
7.4.30.0120.00816.54
7.4.00.0040.01115.01
7.3.330.0000.00613.47
7.3.320.0020.00513.43
7.3.310.0030.00616.46
7.3.300.0050.00316.49
7.3.290.0130.00316.41
7.3.280.0070.01016.46
7.3.270.0220.00017.40
7.3.260.0180.01216.61
7.3.250.0130.00816.70
7.3.240.0090.01716.42
7.3.230.0140.01116.56
7.3.210.0110.01116.54
7.3.200.0130.01319.39
7.3.190.0070.01416.59
7.3.180.0040.01516.64
7.3.170.0130.00416.63
7.3.160.0090.01316.44
7.3.120.0130.00314.94
7.2.330.0110.01116.96
7.2.320.0070.01316.69
7.2.310.0070.01416.80
7.2.300.0270.00316.88
7.2.290.0080.01216.72
7.2.60.0060.01016.96
7.2.00.0070.01019.48
7.1.200.0040.00415.79
7.1.100.0080.00618.38
7.1.70.0070.00417.16
7.1.60.0140.01119.82
7.1.50.0070.01817.05
7.1.00.0070.09022.32
7.0.200.0030.00916.79
7.0.140.0070.07322.10
7.0.60.0030.05019.88
7.0.50.0170.06017.92
7.0.40.0070.04320.32
7.0.30.0470.06020.19
7.0.20.0130.05720.13
7.0.10.0100.08320.08
7.0.00.0130.04320.23
5.6.280.0100.06721.06
5.6.210.0000.04320.73
5.6.200.0000.07018.16
5.6.190.0030.06020.50
5.6.180.0500.05020.67
5.6.170.0500.07020.57
5.6.160.0100.08020.47
5.6.150.0070.06718.20
5.6.140.0130.07718.21
5.6.130.0030.05718.14
5.6.120.0100.09021.02
5.6.110.0130.06321.00
5.6.100.0200.08021.09
5.6.90.0100.07320.99
5.6.80.0070.08020.43
5.5.350.0070.09020.46
5.5.340.0100.08018.09
5.5.330.0100.08720.27
5.5.320.0030.08720.32
5.5.310.0200.04720.25
5.5.300.0000.04317.98
5.5.290.0130.04718.07
5.5.280.0070.04720.87
5.5.270.0030.07020.88
5.5.260.0070.08020.98
5.5.250.0130.07320.71
5.5.240.0130.07020.06
5.4.450.0300.07319.32
5.4.440.0270.03719.16
5.4.430.0130.06019.46
5.4.420.0000.06319.54
5.4.410.0200.04719.42
5.4.400.0830.00018.51
5.4.390.0870.00018.77
5.4.380.0330.05318.55
5.4.370.0230.06318.84
5.4.360.0330.05318.84
5.4.350.0870.04718.61
5.4.340.0170.05718.49
5.4.320.0070.04112.52
5.4.310.0080.04312.52
5.4.300.0110.03812.52
5.4.290.0110.03712.52
5.4.280.0110.03712.42
5.4.270.0040.04012.42
5.4.260.0170.07318.80
5.4.250.0200.07019.08
5.4.240.0100.07018.98
5.4.230.0130.04718.95
5.4.220.0130.05318.65
5.4.210.0100.07318.99
5.4.200.0100.06319.01
5.4.190.0200.04318.74
5.4.180.0100.05018.95
5.4.170.0100.05018.78
5.4.160.0100.05019.00
5.4.150.0100.06018.73
5.4.140.0100.05316.48
5.4.130.0100.04716.36
5.4.120.0130.06316.36
5.4.110.0170.06716.57
5.4.100.0130.05716.46
5.4.90.0100.04716.46
5.4.80.0130.05016.64
5.4.70.0030.05316.44
5.4.60.0170.07016.49
5.4.50.0100.07316.46
5.4.40.0230.06016.60
5.4.30.0100.05016.49
5.4.20.0130.06016.61
5.4.10.0000.05716.34
5.4.00.0100.05015.87
5.3.290.0130.03512.80
5.3.280.0130.04714.79
5.3.270.0200.04314.65
5.3.260.0100.05714.73
5.3.250.0100.07714.65
5.3.240.0100.05014.83
5.3.230.0000.05714.54
5.3.220.0030.05714.61
5.3.210.0200.04314.57
5.3.200.0030.07014.60
5.3.190.0100.07014.61
5.3.180.0100.08014.62
5.3.170.0130.04714.51
5.3.160.0130.04714.51
5.3.150.0100.05014.77
5.3.140.0130.07714.57
5.3.130.0030.06314.66
5.3.120.0200.05014.59
5.3.110.0130.05714.57
5.3.100.0100.07314.07
5.3.90.0070.08314.05
5.3.80.0170.04314.13
5.3.70.0200.06014.12

preferences:
48.9 ms | 401 KiB | 5 Q