3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = array( 1, 2, 3 ); $maxRetries = 5; class RetryCatch { 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)) { $useIterateParams = $iterateParams; array_unshift($useIterateParams, $array[$key]); call_user_func_array($iterateCallback, $useIterateParams); } else { call_user_func($iterateCallback, ($array[$key])); } } else { if (is_array($iterateParams) && !empty($iterateParams)) { $useIterateParams = $iterateParams; array_unshift($useIterateParams, $array[$key]); // var_dump($iterateParams); die(); call_user_func_array(array($iterateCallbackObject, $iterateCallback), $useIterateParams); } 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)) { $useHandleParams = $handleParams; array_unshift($useHandleParams, $e, $array); call_user_func_array($handleCallback, $useHandleParams); } else { call_user_func($handleCallback, $e, $array); } } else { if (is_array($handleParams) && !empty($handleParams)) { $useHandleParams = $handleParams; array_unshift($useHandleParams, $e, $array); call_user_func_array(array($handleCallbackObject, $handleCallback), $useHandleParams); } else { $handleCallbackObject->$handleCallback($e, $array); } } } else { throw new Exception('RetryCatch::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 { RetryCatch::retry($arr, 5, 'RetryCatch::iterate', 'RetryCatch::handleException'); } catch (Exception $e) { } $arr = array(1, false, 2, 3); $foo = new Foo(); try { RetryCatch::retry($arr, 5, 'bar', 'handle', null, null, $foo, $foo); } catch (Exception $e) { } $arr = array(1, false, 2, 3); $foo = new Foo(); try { RetryCatch::retry($arr, 5, 'bar', 'handle', array(1, 2, 3), array(1, 2, 3), $foo, $foo); } catch (Exception $e) { }

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.00818.30
8.3.50.0100.00821.88
8.3.40.0140.00718.88
8.3.30.0110.00619.34
8.3.20.0040.00420.46
8.3.10.0060.00321.95
8.3.00.0090.00022.32
8.2.180.0070.01016.46
8.2.170.0100.00722.96
8.2.160.0070.01020.93
8.2.150.0030.00624.18
8.2.140.0050.00524.66
8.2.130.0030.00626.16
8.2.120.0110.00017.63
8.2.110.0070.00420.39
8.2.100.0060.00617.84
8.2.90.0000.00819.39
8.2.80.0050.00317.97
8.2.70.0000.01017.63
8.2.60.0050.00317.93
8.2.50.0000.00918.07
8.2.40.0030.00718.16
8.2.30.0030.00618.11
8.2.20.0030.00517.88
8.2.10.0030.00617.82
8.2.00.0030.00617.92
8.1.280.0170.00725.92
8.1.270.0060.00322.16
8.1.260.0000.00926.35
8.1.250.0040.00428.09
8.1.240.0130.00022.08
8.1.230.0070.00720.97
8.1.220.0030.00617.74
8.1.210.0060.00318.77
8.1.200.0070.00317.38
8.1.190.0040.00417.53
8.1.180.0080.00018.77
8.1.170.0040.00418.51
8.1.160.0040.00422.10
8.1.150.0040.00418.68
8.1.140.0030.00717.40
8.1.130.0040.00417.89
8.1.120.0000.00817.51
8.1.110.0030.00617.39
8.1.100.0030.00517.52
8.1.90.0030.00617.48
8.1.80.0000.00817.47
8.1.70.0080.00017.39
8.1.60.0140.00017.54
8.1.50.0060.00317.48
8.1.40.0030.00617.45
8.1.30.0070.00317.64
8.1.20.0040.00417.59
8.1.10.0030.00517.61
8.1.00.0040.00417.46
8.0.300.0080.00018.77
8.0.290.0060.00317.18
8.0.280.0000.00818.54
8.0.270.0090.00017.31
8.0.260.0060.00316.84
8.0.250.0000.00817.03
8.0.240.0060.00317.00
8.0.230.0040.00417.06
8.0.220.0020.00516.97
8.0.210.0040.00417.00
8.0.200.0000.00816.96
8.0.190.0090.00017.06
8.0.180.0000.00817.04
8.0.170.0040.00416.89
8.0.160.0040.00416.94
8.0.150.0030.01016.94
8.0.140.0030.00516.89
8.0.130.0030.00313.44
8.0.120.0030.00616.85
8.0.110.0080.00016.93
8.0.100.0090.00017.04
8.0.90.0000.00816.84
8.0.80.0120.00916.97
8.0.70.0060.00316.92
8.0.60.0060.00317.02
8.0.50.0030.00616.89
8.0.30.0130.01117.12
8.0.20.0110.01117.40
8.0.10.0000.00816.94
8.0.00.0110.01216.85
7.4.330.0000.00515.00
7.4.320.0030.00316.71
7.4.300.0000.00716.62
7.4.290.0030.00816.65
7.4.280.0060.00616.60
7.4.270.0040.00416.64
7.4.260.0050.00216.47
7.4.250.0050.00516.62
7.4.240.0040.00416.60
7.4.230.0080.00016.53
7.4.220.0100.01016.41
7.4.210.0100.01116.63
7.4.200.0020.00516.39
7.4.190.0040.00416.77
7.4.160.0040.01616.67
7.4.150.0090.01517.40
7.4.140.0100.01317.86
7.4.130.0120.01016.48
7.4.120.0180.00916.68
7.4.110.0100.01016.52
7.4.100.0230.01016.61
7.4.90.0110.01116.56
7.4.80.0060.02219.39
7.4.70.0170.01116.65
7.4.60.0160.00316.63
7.4.50.0030.00616.58
7.4.40.0110.00722.77
7.4.30.0130.01016.56
7.4.00.0120.00614.99
7.3.330.0000.00613.40
7.3.320.0030.00313.41
7.3.310.0000.01016.50
7.3.300.0090.00016.34
7.3.290.0060.01016.54
7.3.280.0080.01116.45
7.3.270.0170.00317.40
7.3.260.0170.00916.48
7.3.250.0140.01116.59
7.3.240.0080.01716.45
7.3.230.0090.01216.60
7.3.210.0170.00416.75
7.3.200.0170.00316.45
7.3.190.0110.01116.55
7.3.180.0110.00816.49
7.3.170.0140.00716.41
7.3.160.0030.02116.43
7.3.120.0030.01417.15
7.3.110.0080.00817.15
7.3.100.0000.01717.15
7.3.90.0060.01217.15
7.3.80.0000.01917.15
7.3.70.0070.00717.15
7.3.60.0070.01117.15
7.3.50.0060.00917.15
7.3.40.0000.01417.15
7.3.30.0090.00617.15
7.3.20.0030.01317.15
7.3.10.0100.00716.92
7.3.00.0030.01216.95
7.2.330.0130.01016.84
7.2.320.0070.01516.89
7.2.310.0150.00616.50
7.2.300.0100.01016.69
7.2.290.0150.01216.77
7.2.240.0090.00917.15
7.2.230.0110.00417.15
7.2.220.0060.00817.15
7.2.210.0070.01117.15
7.2.200.0030.01317.15
7.2.190.0080.01117.15
7.2.180.0060.00617.15
7.2.170.0070.01317.15
7.2.160.0030.01717.15
7.2.150.0060.00917.15
7.2.140.0100.00617.15
7.2.130.0050.00916.91
7.2.120.0080.00717.14
7.2.110.0090.00816.96
7.2.100.0120.00516.99
7.2.90.0090.00817.05
7.2.80.0080.00717.10
7.2.70.0080.00817.04
7.2.60.0060.01017.03
7.2.50.0080.00817.09
7.2.40.0070.00917.09
7.2.30.0080.01016.94
7.2.20.0070.00816.88
7.2.10.0110.00416.99
7.2.00.0050.01117.82
7.1.330.0060.00617.15
7.1.320.0090.00917.15
7.1.310.0060.01217.15
7.1.300.0060.00917.15
7.1.290.0070.01017.15
7.1.280.0080.00817.15
7.1.270.0070.01017.15
7.1.260.0030.01317.15
7.1.250.0100.00616.41
7.1.200.0000.01815.86
7.1.100.0150.00318.34
7.1.70.0060.01217.28
7.1.60.0130.01319.82
7.1.50.0060.00617.01
7.1.00.0000.08022.50
7.0.200.0030.00716.48
7.0.140.0030.07321.93
7.0.60.0370.05721.87
7.0.50.0070.08317.90
7.0.40.0000.04720.13
7.0.30.0570.06020.06
7.0.20.0230.08320.10
7.0.10.0030.09320.30
7.0.00.0070.08320.09
5.6.280.0030.07720.93
5.6.210.0030.08020.63
5.6.200.0070.06318.28
5.6.190.0070.04720.50
5.6.180.0670.04720.33
5.6.170.0430.06720.54
5.6.160.0070.07720.50
5.6.150.0100.06318.13
5.6.140.0030.09018.27
5.6.130.0200.07018.27
5.6.120.0130.05321.05
5.6.110.0070.08321.01
5.6.100.0000.09320.91
5.6.90.0200.07021.12
5.6.80.0000.05720.53
5.5.350.0070.07720.43
5.5.340.0030.07718.05
5.5.330.0170.05020.44
5.5.320.0030.04320.41
5.5.310.0300.07020.31
5.5.300.0030.04017.98
5.5.290.0070.08017.98
5.5.280.0000.04721.00
5.5.270.0130.08320.89
5.5.260.0070.06020.78
5.5.250.0200.06720.79
5.5.240.0000.05720.07
5.4.450.0270.06719.32
5.4.440.0270.08019.56
5.4.430.0170.05719.52
5.4.420.0230.05019.63
5.4.410.0100.06019.31
5.4.400.1000.00018.53
5.4.390.1170.00018.73
5.4.380.0300.04718.75
5.4.370.1030.04718.55
5.4.360.0870.05718.77
5.4.350.1100.06018.61
5.4.340.0730.06718.61
5.4.320.0100.03712.53
5.4.310.0070.04312.52
5.4.300.0070.04512.53
5.4.290.0070.03912.52
5.4.280.0080.04012.43
5.4.270.0140.03412.43
5.4.260.0170.04718.79
5.4.250.0030.05718.93
5.4.240.0170.05018.92
5.4.230.0070.05318.90
5.4.220.0130.08018.74
5.4.210.0070.05718.82
5.4.200.0070.08718.65
5.4.190.0100.05718.95
5.4.180.0170.04718.82
5.4.170.0170.04718.64
5.4.160.0130.04718.94
5.4.150.0030.05718.94
5.4.140.0030.08016.66
5.4.130.0070.05316.47
5.4.120.0100.05016.41
5.4.110.0130.05016.60
5.4.100.0200.05016.55
5.4.90.0100.05016.55
5.4.80.0130.05016.45
5.4.70.0100.04716.61
5.4.60.0130.04716.50
5.4.50.0070.05016.38
5.4.40.0100.05016.43
5.4.30.0100.06716.33
5.4.20.0130.04716.51
5.4.10.0170.05716.50
5.4.00.0100.05015.82
5.3.290.0060.04112.80
5.3.280.0030.06314.63
5.3.270.0100.05314.57
5.3.260.0170.06714.84
5.3.250.0170.07314.74
5.3.240.0070.05714.56
5.3.230.0200.04714.75
5.3.220.0130.04314.62
5.3.210.0100.05314.70
5.3.200.0030.06314.44
5.3.190.0130.06014.71
5.3.180.0130.04714.70
5.3.170.0100.05014.74
5.3.160.0100.05014.70
5.3.150.0100.05014.77
5.3.140.0070.05314.52
5.3.130.0100.05314.68
5.3.120.0070.05314.73
5.3.110.0170.04714.58
5.3.100.0170.05314.10
5.3.90.0100.05314.25
5.3.80.0070.05314.05
5.3.70.0030.05314.05

preferences:
49.39 ms | 401 KiB | 5 Q