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() { return decorate(['decorator'], function() { 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.0070.01318.30
8.3.60.0100.01018.30
8.3.50.0120.00521.09
8.3.40.0150.00018.98
8.3.30.0100.00618.88
8.3.20.0040.00418.75
8.3.10.0050.00320.71
8.3.00.0040.00423.68
8.2.190.0090.01318.53
8.2.180.0170.00316.88
8.2.170.0160.00622.96
8.2.160.0070.01120.57
8.2.150.0080.00024.18
8.2.140.0080.00024.66
8.2.130.0000.00726.16
8.2.120.0080.00019.38
8.2.110.0070.00321.06
8.2.100.0080.00417.78
8.2.90.0000.00919.27
8.2.80.0060.00318.03
8.2.70.0030.00617.63
8.2.60.0040.00418.05
8.2.50.0040.00418.07
8.2.40.0000.00918.16
8.2.30.0040.00419.78
8.2.20.0040.00417.77
8.2.10.0040.00417.72
8.2.00.0050.00217.71
8.1.280.0100.01025.92
8.1.270.0090.00023.99
8.1.260.0110.00426.35
8.1.250.0040.00428.09
8.1.240.0090.00022.42
8.1.230.0070.00420.88
8.1.220.0040.00418.77
8.1.210.0070.00418.91
8.1.200.0090.00017.23
8.1.190.0000.00817.41
8.1.180.0040.00418.10
8.1.170.0040.00418.74
8.1.160.0070.00018.94
8.1.150.0050.00218.59
8.1.140.0000.00817.37
8.1.130.0000.00717.87
8.1.120.0070.00017.45
8.1.110.0040.00417.53
8.1.100.0000.00717.53
8.1.90.0040.00417.46
8.1.80.0070.00017.43
8.1.70.0000.00817.47
8.1.60.0030.00517.64
8.1.50.0030.00517.42
8.1.40.0050.00317.56
8.1.30.0040.00417.62
8.1.20.0040.00417.74
8.1.10.0040.00417.67
8.1.00.0000.00817.44
8.0.300.0080.00020.04
8.0.290.0000.00716.61
8.0.280.0030.00318.46
8.0.270.0000.00717.34
8.0.260.0040.00416.97
8.0.250.0000.00717.00
8.0.240.0080.00016.96
8.0.230.0000.00717.08
8.0.220.0030.00316.92
8.0.210.0040.00416.99
8.0.200.0000.00717.08
8.0.190.0000.00816.98
8.0.180.0030.00617.05
8.0.170.0050.00216.88
8.0.160.0040.00417.04
8.0.150.0040.00417.02
8.0.140.0070.00416.87
8.0.130.0030.00313.49
8.0.120.0040.00416.97
8.0.110.0040.00416.85
8.0.100.0000.00816.81
8.0.90.0000.00716.82
8.0.80.0150.00016.93
8.0.70.0020.00516.94
8.0.60.0000.00817.13
8.0.50.0060.00316.95
8.0.30.0180.00817.22
8.0.20.0130.00517.41
8.0.10.0040.00417.06
8.0.00.0100.00816.83
7.4.330.0050.00014.84
7.4.320.0080.00016.57
7.4.300.0040.00416.64
7.4.290.0040.00416.56
7.4.280.0000.00816.50
7.4.270.0000.00816.72
7.4.260.0000.00613.35
7.4.250.0000.00716.52
7.4.240.0030.00516.65
7.4.230.0030.00316.71
7.4.220.0000.02216.60
7.4.210.0070.00716.61
7.4.200.0070.00016.68
7.4.190.0030.00316.61
7.4.160.0060.00916.56
7.4.150.0120.00617.40
7.4.140.0070.01017.86
7.4.130.0120.00516.66
7.4.120.0050.01216.65
7.4.110.0140.00316.57
7.4.100.0150.00316.73
7.4.90.0070.01116.53
7.4.80.0090.00919.04
7.4.70.0330.00316.46
7.4.60.0000.01716.63
7.4.50.0060.00316.75
7.4.40.0080.00822.27
7.4.30.0120.01316.45
7.4.00.0100.00714.98
7.3.330.0050.00013.48
7.3.320.0030.00313.44
7.3.310.0000.00716.30
7.3.300.0060.00016.50
7.3.290.0080.00516.43
7.3.280.0070.00916.49
7.3.270.0060.01217.40
7.3.260.0120.00518.24
7.3.250.0100.00716.45
7.3.240.0150.00916.55
7.3.230.0080.01616.70
7.3.210.0040.01616.58
7.3.200.0110.01119.39
7.3.190.0090.01216.52
7.3.180.0070.01016.44
7.3.170.0120.00616.48
7.3.160.0120.00316.55
7.3.120.0090.00614.86
7.3.00.0030.01016.48
7.2.330.0100.00716.62
7.2.320.0050.01316.72
7.2.310.0100.01016.52
7.2.300.0050.01116.51
7.2.290.0100.00716.68
7.2.130.0130.00017.01
7.2.120.0080.00617.02
7.2.110.0060.00916.68
7.2.100.0030.00716.92
7.2.90.0120.00316.81
7.2.80.0130.00016.82
7.2.70.0070.00717.14
7.2.60.0050.01016.77
7.2.50.0030.00717.05
7.2.40.0040.01216.64
7.2.30.0000.01516.74
7.2.20.0030.01016.87
7.2.10.0000.01316.71
7.2.00.0020.01218.12
7.1.250.0080.00615.84
7.1.240.0000.01415.55
7.1.230.0120.00315.82
7.1.220.0030.01215.77
7.1.210.0080.00815.73
7.1.200.0030.00915.77
7.1.190.0000.00815.84
7.1.180.0090.00015.77
7.1.170.0000.01015.83
7.1.160.0110.00415.57
7.1.150.0040.00815.54
7.1.140.0070.00715.95
7.1.130.0000.01515.76
7.1.120.0000.01115.76
7.1.110.0070.00315.87
7.1.100.0070.00715.51
7.1.90.0100.00015.93
7.1.80.0060.00615.62
7.1.70.0030.00516.54
7.1.60.0030.00816.58
7.1.50.0060.01016.39
7.1.40.0030.01015.86
7.1.30.0060.00315.89
7.1.20.0000.00815.68
7.1.10.0030.00715.76
7.1.00.0080.02519.06
7.0.330.0030.00815.05
7.0.320.0060.00315.20
7.0.310.0060.00815.19
7.0.300.0110.00014.82
7.0.290.0060.00615.09
7.0.280.0060.00915.11
7.0.270.0000.00715.25
7.0.260.0030.00915.21
7.0.250.0040.00715.41
7.0.240.0070.00415.48
7.0.230.0030.00615.31
7.0.220.0090.00015.16
7.0.210.0030.00615.48
7.0.200.0050.00916.02
7.0.190.0040.00815.48
7.0.180.0040.01115.02
7.0.170.0060.00615.35
7.0.160.0030.00915.30
7.0.150.0070.00315.32
7.0.140.0070.03818.75
7.0.130.0070.00715.33
7.0.120.0040.00415.49
7.0.110.0100.02017.53
7.0.100.0080.02817.57
7.0.90.0080.03017.75
7.0.80.0050.02217.55
7.0.70.0030.03117.68
7.0.60.0070.02717.69
7.0.50.0080.02217.74
7.0.40.0050.03216.71
7.0.30.0050.02316.78
7.0.20.0010.02816.77
7.0.10.0050.02216.73
7.0.00.0080.02416.88
5.6.380.0030.00714.06
5.6.370.0100.00314.34
5.6.360.0080.00514.54
5.6.350.0070.00714.35
5.6.340.0060.00614.61
5.6.330.0100.00314.52
5.6.320.0060.00614.50
5.6.310.0030.01014.14
5.6.300.0030.00714.04
5.6.290.0000.01314.38
5.6.280.0020.04217.87
5.6.270.0090.00314.34
5.6.260.0100.02017.49
5.6.250.0080.02717.70
5.6.240.0050.03217.49
5.6.230.0070.02217.56
5.6.220.0030.03617.61
5.6.210.0050.02517.61
5.6.200.0030.02517.89
5.6.190.0050.02517.65
5.6.180.0050.03317.72
5.6.170.0050.02217.89
5.6.160.0070.03017.75
5.6.150.0030.02417.80
5.6.140.0100.02017.68
5.6.130.0040.02417.83
5.6.120.0110.01817.70
5.6.110.0050.02717.72
5.6.100.0080.03017.77
5.6.90.0070.04517.90
5.6.80.0080.04117.41
5.6.70.0030.04717.25
5.6.60.0070.04017.38
5.6.50.0070.04317.56
5.6.40.0080.04017.35
5.6.30.0080.04117.33
5.6.20.0080.04317.60
5.6.10.0040.04317.36
5.6.00.0080.04317.40
5.5.380.0100.01715.66
5.5.370.0090.02215.79
5.5.360.0050.02015.73
5.5.350.0070.02715.95
5.5.340.0020.02616.08
5.5.330.0050.02215.97
5.5.320.0050.02115.96
5.5.310.0050.02415.99
5.5.300.0000.02516.13
5.5.290.0070.02315.94
5.5.280.0020.02816.18
5.5.270.0040.02316.02
5.5.260.0050.03015.96
5.5.250.0060.02015.65
5.5.240.0050.02315.74
5.5.230.0030.04515.85
5.5.220.0070.03015.85
5.5.210.0070.04215.63
5.5.200.0050.02415.72
5.5.190.0040.03915.62
5.5.180.0020.02715.66
5.5.170.0090.00311.08
5.5.160.0100.03515.83
5.5.150.0050.04015.53
5.5.140.0050.04115.65
5.5.130.0030.04215.62
5.5.120.0060.03815.55
5.5.110.0050.04115.66
5.5.100.0020.03115.59
5.5.90.0070.03415.55
5.5.80.0050.02815.64
5.5.70.0020.02615.40
5.5.60.0100.03315.52
5.5.50.0080.03815.64
5.5.40.0050.02015.72
5.5.30.0030.04215.56
5.5.20.0030.04215.69
5.5.10.0030.04015.56
5.5.00.0020.04215.75
5.4.450.0030.02515.30
5.4.440.0070.03715.11
5.4.430.0030.02915.37
5.4.420.0050.02815.19
5.4.410.0070.02014.94
5.4.400.0100.03715.05
5.4.390.0100.02815.08
5.4.380.0070.03715.18
5.4.370.0100.02815.04
5.4.360.0100.03815.06
5.4.350.0030.04115.21
5.4.340.0050.04215.02
5.4.330.0030.00710.72
5.4.320.0030.02715.17
5.4.310.0080.03615.19
5.4.300.0080.02315.16
5.4.290.0050.01815.08
5.4.280.0070.03715.04
5.4.270.0080.03715.02
5.4.260.0050.03614.92
5.4.250.0050.03714.95
5.4.240.0070.03915.09
5.4.230.0050.03914.97
5.4.220.0020.04415.00
5.4.210.0030.03714.83
5.4.200.0050.04214.98
5.4.190.0040.03914.86
5.4.180.0030.04415.02
5.4.170.0100.03914.91
5.4.160.0030.03815.08
5.4.150.0020.04414.96
5.4.140.0110.01813.70
5.4.130.0070.03813.70
5.4.120.0020.03913.51
5.4.110.0050.03713.68
5.4.100.0030.03513.54
5.4.90.0020.04013.89
5.4.80.0070.03713.93
5.4.70.0030.02513.79
5.4.60.0050.03913.59
5.4.50.0040.04213.88
5.4.40.0050.03813.67
5.4.30.0080.03613.45
5.4.20.0030.03913.89
5.4.10.0090.03313.76
5.4.00.0070.03513.47
5.3.290.0050.03712.53
5.3.280.0020.03612.44
5.3.270.0050.04212.52
5.3.260.0030.04312.60
5.3.250.0030.04012.53
5.3.240.0050.04012.53
5.3.230.0050.03312.39
5.3.220.0070.03412.47
5.3.210.0070.03712.55
5.3.200.0030.03712.48
5.3.190.0080.03812.62
5.3.180.0060.02312.62
5.3.170.0070.03412.64
5.3.160.0050.02512.60
5.3.150.0130.03312.43
5.3.140.0030.03212.63
5.3.130.0050.04312.36
5.3.120.0120.02512.52
5.3.110.0080.03312.54
5.3.100.0020.02712.22
5.3.90.0100.02812.20
5.3.80.0030.02412.17
5.3.70.0030.04212.26
5.3.60.0030.03612.27
5.3.50.0080.03712.22
5.3.40.0040.04212.13
5.3.30.0030.04212.15
5.3.20.0110.03212.11
5.3.10.0090.02512.09
5.3.00.0020.04211.95
5.2.170.0030.01811.55
5.2.160.0030.03311.55
5.2.150.0030.02511.55
5.2.140.0050.03511.55
5.2.130.0070.03011.55
5.2.120.0070.02811.55
5.2.110.0120.02411.55
5.2.100.0070.02811.55
5.2.90.0030.02611.55
5.2.80.0020.03611.55
5.2.70.0030.03511.55
5.2.60.0030.03011.55
5.2.50.0010.02311.55
5.2.40.0050.03111.55
5.2.30.0030.02811.55
5.2.20.0080.01511.55
5.2.10.0080.02811.55
5.2.00.0050.02711.55
5.1.60.0050.02511.55
5.1.50.0030.02011.55
5.1.40.0050.02211.55
5.1.30.0050.02811.55
5.1.20.0000.03511.55
5.1.10.0030.02611.55
5.1.00.0060.01311.55
5.0.50.0040.02211.55
5.0.40.0030.02511.55
5.0.30.0040.03411.55
5.0.20.0020.02311.55
5.0.10.0030.02111.55
5.0.00.0030.02311.55
4.4.90.0020.01711.55
4.4.80.0050.01611.55
4.4.70.0060.01711.55
4.4.60.0010.02011.55
4.4.50.0080.01311.55
4.4.40.0010.02111.55
4.4.30.0070.01211.55
4.4.20.0020.01511.55
4.4.10.0020.02011.55
4.4.00.0020.02911.55
4.3.110.0020.01911.55
4.3.100.0080.01511.55
4.3.90.0030.01811.55
4.3.80.0010.01611.55
4.3.70.0030.01811.55
4.3.60.0070.01511.55
4.3.50.0010.02011.55
4.3.40.0050.02711.55
4.3.30.0020.02011.55
4.3.20.0030.01711.55
4.3.10.0000.01811.55
4.3.00.0000.01811.55

preferences:
60.86 ms | 401 KiB | 5 Q