3v4l.org

run code in 300+ PHP versions simultaneously
<?php function decorate(array $decorators, callable $fn, array $arguments = array()) { foreach (array_reverse($decorators) as $decorator) { if (is_callable($decorator)) { $fn = $decorator($fn); } } return call_user_func_array($fn, $arguments); } function decorator(callable $decorator) { // This function replaces 'trace' return function($wrapped) use ($decorator) { // This function replaces the function which 'trace' is used on. return function() use ($wrapped, $decorator) { var_dump($wrapped); $arguments = func_get_args(); return call_user_func($decorator, $wrapped, $arguments); }; }; } function expects(/* $type,... */) { $types = func_get_args(); $decorator = function(callable $fn) use ($types) { $wrapper = function() use ($fn, $types) { foreach (func_get_args() as $i => $arg) { if (($type = gettype($arg)) !== $types[$i] and isset($types[$i]) and $types[$i] !== 'mixed') { throw new \InvalidArgumentException("Expected type of argument $i to be {$types[$i]}, got $type"); } } return call_user_func_array($fn, func_get_args()); }; return $wrapper; }; return $decorator; } function returns($type) { $decorator = function($fn) use ($type) { $wrapper = function() use ($fn, $type) { $returnValue = call_user_func_array($fn, func_get_args()); if (($returnType = gettype($returnValue)) !== $type) { throw new \UnexpectedValueException("Expected return type $type, got $returnType"); } return $returnValue; }; return $wrapper; }; return $decorator; } function trace(callable $fn, array $arguments) { return decorate( ['decorator'], function($fn, $arguments) { printf("Calling %s with arguments %s\n", print_r($fn, true), print_r($arguments, true)); return call_user_func_array($fn, $arguments); }, func_get_args() ); } function foo() { return decorate(['trace'], function() { echo "Hello World\n"; }, func_get_args()); } function bar() { return decorate( [returns('string')], function() { return "foo"; }, func_get_args() ); } foo(); bar();

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.70.0150.00316.73
8.3.60.0120.00318.43
8.3.50.0080.00821.93
8.3.40.0150.00618.97
8.3.30.0070.00718.78
8.3.20.0050.00318.82
8.3.10.0040.00421.05
8.3.00.0070.00423.70
8.2.180.0120.00916.75
8.2.170.0110.01122.96
8.2.160.0070.01020.22
8.2.150.0050.00324.18
8.2.140.0070.00024.66
8.2.130.0040.00426.16
8.2.120.0040.00419.23
8.2.110.0050.00520.47
8.2.100.0120.00017.78
8.2.90.0040.00419.05
8.2.80.0060.00317.97
8.2.70.0080.00017.50
8.2.60.0080.00017.93
8.2.50.0080.00018.07
8.2.40.0000.00818.28
8.2.30.0040.00419.89
8.2.20.0040.00417.81
8.2.10.0040.00417.84
8.2.00.0040.00717.74
8.1.280.0120.00325.92
8.1.270.0030.00523.99
8.1.260.0150.00426.35
8.1.250.0000.00828.09
8.1.240.0090.00022.48
8.1.230.0040.00820.87
8.1.220.0080.00018.77
8.1.210.0040.00419.03
8.1.200.0060.00317.36
8.1.190.0000.00817.50
8.1.180.0050.00318.10
8.1.170.0030.00518.67
8.1.160.0000.00718.78
8.1.150.0040.00418.49
8.1.140.0040.00417.33
8.1.130.0040.00417.67
8.1.120.0040.00417.49
8.1.110.0000.00717.42
8.1.100.0040.00417.31
8.1.90.0000.00717.34
8.1.80.0000.00717.45
8.1.70.0040.00417.44
8.1.60.0060.00317.46
8.1.50.0030.00517.52
8.1.40.0030.00517.55
8.1.30.0040.00417.61
8.1.20.0040.00417.62
8.1.10.0040.00417.46
8.1.00.0070.00317.38
8.0.300.0070.00019.85
8.0.290.0000.00717.05
8.0.280.0030.00418.48
8.0.270.0000.00717.23
8.0.260.0000.00716.93
8.0.250.0000.00817.00
8.0.240.0000.00816.97
8.0.230.0040.00416.96
8.0.220.0000.00716.95
8.0.210.0070.00016.89
8.0.200.0000.00716.97
8.0.190.0040.00417.04
8.0.180.0040.00417.00
8.0.170.0060.00316.88
8.0.160.0050.00216.89
8.0.150.0000.00716.82
8.0.140.0050.00516.93
8.0.130.0060.00013.57
8.0.120.0000.00717.01
8.0.110.0070.00016.89
8.0.100.0040.00417.00
8.0.90.0000.00717.04
8.0.80.0060.01117.01
8.0.70.0040.00417.03
8.0.60.0040.00417.03
8.0.50.0030.00617.04
8.0.30.0120.00917.40
8.0.20.0090.01017.40
8.0.10.0050.00317.15
8.0.00.0160.00516.80
7.4.330.0050.00014.73
7.4.320.0030.00316.57
7.4.300.0030.00616.65
7.4.290.0020.00516.67
7.4.280.0000.00716.52
7.4.270.0030.00316.46
7.4.260.0000.00613.31
7.4.250.0040.00416.63
7.4.240.0070.00016.55
7.4.230.0000.00816.68
7.4.220.0100.01016.75
7.4.210.0060.00916.56
7.4.200.0030.00316.40
7.4.190.0060.00316.71
7.4.160.0100.00716.56
7.4.150.0140.00417.40
7.4.140.0090.01217.86
7.4.130.0120.00516.68
7.4.120.0110.00616.63
7.4.110.0070.01016.63
7.4.100.0150.00916.42
7.4.90.0070.01116.71
7.4.80.0060.01119.37
7.4.70.0190.00316.49
7.4.60.0100.00716.23
7.4.50.0040.00416.69
7.4.40.0070.01022.27
7.4.30.0130.00716.46
7.4.00.0000.01514.65
7.3.330.0000.00513.27
7.3.320.0060.00013.22
7.3.310.0030.00316.37
7.3.300.0030.00316.33
7.3.290.0020.01216.37
7.3.280.0090.00716.34
7.3.270.0090.00917.40
7.3.260.0060.01318.24
7.3.250.0170.00816.42
7.3.240.0100.00616.58
7.3.230.0090.00916.46
7.3.210.0060.01616.45
7.3.200.0030.00619.39
7.3.190.0100.00716.44
7.3.180.0120.00616.49
7.3.170.0080.00816.43
7.3.160.0100.00716.56
7.3.120.0060.00915.01
7.2.330.0150.00416.78
7.2.320.0000.01616.71
7.2.310.0190.01516.68
7.2.300.0060.01016.55
7.2.290.0140.00416.64
7.2.60.0190.00316.68
7.2.00.0070.01119.53
7.1.200.0090.00615.34
7.1.100.0060.00617.97
7.1.70.0000.01017.19
7.1.60.0090.01619.40
7.1.50.0100.01416.90
7.1.00.0000.05022.41
7.0.200.0030.00616.90
7.0.140.0030.07022.20
7.0.70.0070.07721.68
7.0.60.0030.06021.77
7.0.50.0030.05722.11
7.0.40.0170.06720.11
7.0.30.0030.07720.18
7.0.20.0070.05019.95
7.0.10.0070.06320.04
7.0.00.0030.07719.99
5.6.280.0070.07020.81
5.6.220.0070.08720.57
5.6.210.0100.06320.75
5.6.200.0030.08321.19
5.6.190.0070.08021.00
5.6.180.0000.04321.09
5.6.170.0070.06721.01
5.6.160.0070.06720.99
5.6.150.0070.08721.14
5.6.140.0130.06321.00
5.6.130.0030.05721.02
5.6.120.0030.08721.07
5.6.110.0030.08021.21
5.6.100.0070.04321.15
5.6.90.0030.05720.97
5.6.80.0030.09020.48
5.6.70.0070.04320.38
5.6.60.0000.08320.44
5.6.50.0030.06020.49
5.6.40.0070.06720.43
5.6.30.0070.06320.34
5.6.20.0030.07720.48
5.6.10.0070.06320.41
5.6.00.0030.06320.33
5.5.360.0070.06720.37
5.5.350.0070.08020.45
5.5.340.0070.08320.80
5.5.330.0070.08020.89
5.5.320.0070.03720.95
5.5.310.0070.07720.85
5.5.300.0100.08020.94
5.5.290.0000.06320.69
5.5.280.0070.04720.91
5.5.270.0100.07720.85
5.5.260.0070.05320.90
5.5.250.0070.05720.75
5.5.240.0070.07320.30
5.5.230.0030.09720.25
5.5.220.0000.07020.20
5.5.210.0000.08320.18
5.5.200.0000.08020.24
5.5.190.0130.07020.16
5.5.180.0070.07020.26
5.5.160.0100.07720.03
5.5.150.0070.05020.16
5.5.140.0030.05320.29
5.5.130.0030.06320.17
5.5.120.0000.06320.19
5.5.110.0000.06020.19
5.5.100.0100.07720.15
5.5.90.0070.07720.11
5.5.80.0100.07020.13
5.5.70.0030.06320.13
5.5.60.0030.07320.20
5.5.50.0070.06320.16
5.5.40.0100.07320.01
5.5.30.0070.07720.20
5.5.20.0000.06020.12
5.5.10.0070.07720.07
5.5.00.0070.05020.02
5.4.450.0100.07019.51
5.4.440.0030.08019.56
5.4.430.0000.05719.20
5.4.420.0000.05719.41
5.4.410.0000.08719.34
5.4.400.0030.06319.05
5.4.390.0030.06318.90
5.4.380.0070.07319.04
5.4.370.0030.04718.88
5.4.360.0030.08018.85
5.4.350.0130.07019.07
5.4.340.0070.05019.04
5.4.320.0100.08019.13
5.4.310.0070.07019.03
5.4.300.0100.06719.12
5.4.290.0030.03719.05
5.4.280.0030.06019.12
5.4.270.0000.08019.09
5.4.260.0070.04719.03
5.4.250.0030.08019.03
5.4.240.0100.07319.12
5.4.230.0100.05319.21
5.4.220.0030.07319.15
5.4.210.0000.06318.90
5.4.200.0000.06719.11
5.4.190.0000.07319.17
5.4.180.0070.07719.13
5.4.170.0070.07019.13
5.4.160.0070.04319.21
5.4.150.0070.06019.01
5.4.140.0030.08016.43
5.4.130.0070.06316.42
5.4.120.0100.04716.45
5.4.110.0030.07316.48
5.4.100.0030.06316.57
5.4.90.0070.03316.32
5.4.80.0030.07716.54
5.4.70.0070.06716.48
5.4.60.0000.05316.38
5.4.50.0030.07716.51
5.4.40.0030.06316.45
5.4.30.0030.06716.52
5.4.20.0000.05016.49
5.4.10.0000.05016.51
5.4.00.0070.04715.86
5.3.290.0030.07314.81
5.3.280.0000.07314.70
5.3.270.0100.07014.70
5.3.260.0100.06014.70
5.3.250.0030.05314.70
5.3.240.0000.06714.79
5.3.230.0130.05014.72
5.3.220.0030.06014.71
5.3.210.0100.05014.70
5.3.200.0000.06014.70
5.3.190.0070.04714.70
5.3.180.0000.04314.73
5.3.170.0070.05014.70
5.3.160.0000.05314.70
5.3.150.0030.05314.70
5.3.140.0030.05014.70
5.3.130.0030.04014.70
5.3.120.0030.06014.70
5.3.110.0000.05014.70
5.3.100.0030.05314.70
5.3.90.0030.05014.70
5.3.80.0070.07014.70
5.3.70.0030.05014.70
5.3.60.0070.07314.70
5.3.50.0070.04314.70
5.3.40.0000.06714.70
5.3.30.0070.07314.70
5.3.20.0030.05714.70
5.3.10.0070.05314.70
5.3.00.0070.05014.70
5.2.170.0030.03014.70
5.2.160.0030.04714.70
5.2.150.0030.05314.70
5.2.140.0030.06014.70
5.2.130.0100.05314.70
5.2.120.0000.06014.70
5.2.110.0030.05014.70
5.2.100.0030.06014.70
5.2.90.0000.06314.70
5.2.80.0030.05314.70
5.2.70.0000.05714.70
5.2.60.0100.05314.70
5.2.50.0000.04014.70
5.2.40.0030.04714.70
5.2.30.0000.05314.70
5.2.20.0030.03714.70
5.2.10.0000.04714.70
5.2.00.0030.04014.70
5.1.60.0030.03314.70
5.1.50.0000.04314.70
5.1.40.0030.03014.70
5.1.30.0000.04314.70
5.1.20.0070.05714.70
5.1.10.0070.05014.70
5.1.00.0030.04014.70
5.0.50.0030.03014.70
5.0.40.0000.04014.70
5.0.30.0100.06014.70
5.0.20.0030.04014.70
5.0.10.0000.04014.70
5.0.00.0070.05014.70
4.4.90.0030.03714.70
4.4.80.0030.03314.70
4.4.70.0000.01714.70
4.4.60.0000.02014.70
4.4.50.0030.03014.70
4.4.40.0030.05014.70
4.4.30.0000.03714.70
4.4.20.0000.03714.70
4.4.10.0000.03714.70
4.4.00.0030.05314.70
4.3.110.0030.02714.70
4.3.100.0000.03014.70
4.3.90.0000.02714.70
4.3.80.0000.04314.70
4.3.70.0030.03714.70
4.3.60.0000.02314.70
4.3.50.0000.03714.70
4.3.40.0000.05314.70
4.3.30.0000.03014.70
4.3.20.0000.03314.70
4.3.10.0000.03314.70
4.3.00.0070.03314.70

preferences:
43.03 ms | 401 KiB | 5 Q