3v4l.org

run code in 300+ PHP versions simultaneously
<?php # Arrow Functions 2.0 `Short Closures` # OLD WAY (PHP < 7.4 ) function cube($arg){ return ($arg * $arg * $arg); } $b = array_map('cube', range(1, 5)); var_dump('Short closure old syntax', $b); # OR $b = array_map(function($a2) {return ($a2 * $a2 * $a2);}, range(1, 5)); var_dump('Short closure old syntax variant', $b); # ONLY FOR PHP 7.4 + #/!\ MORE CLEAR PHP CODE BEST PRACTIVE /!\ $b = array_map(fn($n) => $n * $n * $n, range(1, 5)); var_dump('Arrow Function 7.4 + syntax', $b); # OLD Example with closure herit in parent scope with `use` syntax $factor = 10; $oldcalc = function(int $num) use ($factor): int { return $num * $factor; }; var_dump('Short closure old syntax', $oldcalc(2)); # PHP 7.4 + syntax it allows us to build more readable and maintainable code. $oldcalc = fn(int $num): int => $num * $factor; var_dump('Arrow Function 7.4 + syntax', $oldcalc(2));

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.130.0120.00917.60
8.4.120.0110.00924.01
8.4.110.0110.00818.98
8.4.100.0120.00817.66
8.4.90.0130.00720.38
8.4.80.0100.01119.02
8.4.70.0040.00420.60
8.4.60.0070.00920.76
8.4.50.0080.00724.24
8.4.40.0070.00417.66
8.4.30.0140.00718.64
8.4.20.0100.01019.62
8.4.10.0000.01619.52
8.3.260.0080.01116.63
8.3.250.0150.00516.64
8.3.240.0070.01117.13
8.3.230.0130.00716.79
8.3.220.0110.00918.83
8.3.210.0130.00816.52
8.3.200.0110.00816.61
8.3.190.0050.00317.04
8.3.180.0070.01020.88
8.3.170.0070.01117.07
8.3.160.0120.00616.85
8.3.150.0060.01516.74
8.3.140.0040.00418.36
8.3.130.0060.00316.57
8.3.120.0060.00318.91
8.3.110.0140.00420.94
8.3.100.0070.00324.06
8.3.90.0000.00826.77
8.3.80.0100.00016.38
8.3.70.0100.00516.58
8.3.60.0150.00018.18
8.3.50.0080.00523.64
8.3.40.0090.00619.33
8.3.30.0120.00318.75
8.3.20.0030.00520.72
8.3.10.0060.00320.15
8.3.00.0040.00422.43
8.2.290.0150.00520.05
8.2.280.0050.00618.80
8.2.270.0060.01016.77
8.2.260.0080.00017.34
8.2.250.0110.00717.00
8.2.240.0120.00618.90
8.2.230.0060.00322.58
8.2.220.0040.01137.54
8.2.210.0080.00026.77
8.2.200.0040.00416.63
8.2.190.0170.00716.63
8.2.180.0090.00618.41
8.2.170.0070.01422.96
8.2.160.0140.00021.05
8.2.150.0060.00324.18
8.2.140.0080.00024.66
8.2.130.0070.00026.16
8.2.120.0040.00419.72
8.2.110.0070.00321.93
8.2.100.0070.00417.84
8.2.90.0060.00317.63
8.2.80.0040.00418.78
8.2.70.0000.00817.48
8.2.60.0030.00517.50
8.2.50.0000.00818.05
8.2.40.0040.00418.22
8.2.30.0070.00019.44
8.2.20.0000.00718.14
8.2.10.0070.00019.25
8.2.00.0000.00819.19
8.1.330.0110.00821.80
8.1.320.0100.01015.97
8.1.310.0070.01116.76
8.1.300.0060.00316.05
8.1.290.0140.00018.88
8.1.280.0120.00325.92
8.1.270.0040.00422.14
8.1.260.0000.00826.35
8.1.250.0070.00028.09
8.1.240.0090.00023.85
8.1.230.0040.00719.10
8.1.220.0000.00817.74
8.1.210.0000.00818.77
8.1.200.0000.00917.54
8.1.190.0080.00017.36
8.1.180.0050.00318.10
8.1.170.0030.00517.62
8.1.160.0040.00418.77
8.1.150.0040.00418.92
8.1.140.0000.00718.84
8.1.130.0070.00021.79
8.1.120.0070.00017.48
8.1.110.0070.00017.50
8.1.100.0000.00817.45
8.1.90.0040.00417.47
8.1.80.0030.00517.35
8.1.70.0030.00317.44
8.1.60.0000.00817.59
8.1.50.0040.00417.54
8.1.40.0000.00817.59
8.1.30.0000.00817.72
8.1.20.0030.00617.59
8.1.10.0030.00617.50
8.1.00.0060.00617.55
8.0.300.0050.00319.64
8.0.290.0070.00016.75
8.0.280.0040.00418.31
8.0.270.0070.00018.01
8.0.260.0070.00020.05
8.0.250.0060.00016.99
8.0.240.0000.00616.95
8.0.230.0040.00416.99
8.0.220.0030.00316.92
8.0.210.0030.00616.89
8.0.200.0030.00316.96
8.0.190.0040.00416.95
8.0.180.0000.00816.91
8.0.170.0000.01016.90
8.0.160.0070.00016.78
8.0.150.0030.00316.92
8.0.140.0000.01016.85
8.0.130.0050.00013.33
8.0.120.0040.00416.85
8.0.110.0040.00416.94
8.0.100.0000.00716.91
8.0.90.0060.00316.88
8.0.80.0020.01316.87
8.0.70.0050.00216.80
8.0.60.0000.00716.70
8.0.50.0000.00816.95
8.0.30.0070.01017.13
8.0.20.0100.01116.90
8.0.10.0040.00416.91
8.0.00.0120.00616.55
7.4.330.0000.00515.55
7.4.320.0060.00016.62
7.4.300.0070.00016.61
7.4.290.0000.00816.41
7.4.280.0090.00016.39
7.4.270.0080.00416.50
7.4.260.0000.00513.30
7.4.250.0070.00016.55
7.4.240.0010.00616.57
7.4.230.0050.00316.39
7.4.220.0040.00316.55
7.4.210.0070.00816.61
7.4.200.0080.00016.58
7.4.130.0100.00816.56
7.4.120.0090.01516.49
7.4.110.0130.00316.50
7.4.100.0120.00716.55
7.4.90.0130.00516.41
7.4.80.0030.01419.39
7.4.70.0050.01116.54
7.4.60.0060.01316.50
7.4.50.0130.00316.38
7.4.40.0030.01516.46
7.4.30.0080.01016.53
7.4.20.0060.01316.29
7.4.10.0120.00716.51
7.4.00.0110.00916.63
7.3.330.0040.00416.09
7.3.320.0000.00513.11
7.3.310.0040.00416.23
7.3.300.0030.00316.05
7.3.290.0100.00916.18
7.3.280.0120.00916.07
7.3.260.0040.01916.14
7.3.240.0100.00716.18
7.3.230.0070.01016.15
7.3.210.0130.00416.25
7.3.200.0000.01716.42
7.3.190.0090.00616.13
7.3.180.0110.00416.23
7.3.170.0060.01116.31
7.3.160.0050.01016.21
7.3.150.0100.00816.27
7.3.140.0130.00516.27
7.3.130.0110.00916.21
7.3.120.0140.00516.35
7.3.110.0090.01016.35
7.3.100.0050.01116.25
7.3.90.0110.00816.27
7.3.80.0100.00816.26
7.3.70.0080.00916.06
7.3.60.0110.00516.13
7.3.50.0070.01016.17
7.3.40.0100.00616.19
7.3.30.0080.00916.20
7.3.20.0090.00816.26
7.3.10.0100.00716.17
7.3.00.0070.00916.25
7.2.330.0140.00516.48
7.2.320.0060.01016.50
7.2.310.0100.00616.47
7.2.300.0030.01316.16
7.2.290.0160.00016.55
7.2.280.0150.00416.31
7.2.270.0040.01716.49
7.2.260.0090.01016.33
7.2.250.0100.00916.16
7.2.240.0100.00716.36
7.2.230.0080.01016.42
7.2.220.0050.01116.23
7.2.210.0090.01016.26
7.2.200.0060.01116.26
7.2.190.0070.01016.27
7.2.180.0060.01116.36
7.2.170.0090.00716.26
7.2.160.0080.00816.40
7.2.150.0100.00716.28
7.2.140.0110.00616.46
7.2.130.0080.00916.33
7.2.120.0130.00616.33
7.2.110.0100.00816.52
7.2.100.0110.00616.41
7.2.90.0080.00816.33
7.2.80.0090.00916.34
7.2.70.0100.00816.31
7.2.60.0090.01416.34
7.2.50.0100.01016.25
7.2.40.0090.01116.40
7.2.30.0100.01316.33
7.2.20.0080.01316.36
7.2.10.0070.01416.34
7.2.00.0090.01216.32

preferences:
119.78 ms | 403 KiB | 5 Q