3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * PHP 5.6 example of "Functional Options" as presented by Rob Pike * in his article "Self-referential functions and the design of options" * http://commandcenter.blogspot.com.au/2014/01/self-referential-functions-and-design.html */ namespace Mailer { class Mailer { private $host; private $lazy = false; public function __construct($host, ...$options) { $this->host = $host; foreach ($options as $option) { $option($this); } } // Wish this could be a private function and still be // invoked by an options function so it's not mutable from the outside public function setLazy($lazy) { $this->lazy = $lazy; } public function isLazy() { return $this->lazy; } } } namespace Mailer\Options { class Lazy { public function __invoke(Mailer $mailer) { $mailer->setLazy(true); } } function SuperLazy() { return function(\Mailer\Mailer $mailer) { $mailer->setLazy(true); }; } } namespace { use function \Mailer\Options\SuperLazy; $tls = function (\Mailer\Mailer $mailer) { echo 'LOL Lets do some TLS --'; }; // Any one of these $lazy vars can be passed as an option $lazy1 = function (\Mailer\Mailer $mailer) { $mailer->setLazy(true); }; $lazy2 = new \Mailer\Options\Lazy; $lazy3 = SuperLazy(); // Ughhh, I want to do `$lazy3 = SuperLazy;` but PHP won't let me $mailer = new \Mailer\Mailer('www.gmail.com', $tls, $lazy3); echo $mailer->isLazy() ? 'Yes lazy' : 'No lazy'; }

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.120.0090.00822.23
8.4.110.0130.00722.40
8.4.100.0090.00118.98
8.4.90.0120.00917.68
8.4.80.0110.00922.48
8.4.70.0130.00917.84
8.4.60.0110.00918.91
8.4.50.0140.00817.51
8.4.40.0120.00917.77
8.4.30.0120.00917.88
8.4.20.0160.00317.63
8.4.10.0050.00517.43
8.3.250.0100.01018.66
8.3.240.0120.00716.55
8.3.230.0120.00716.63
8.3.220.0050.00217.10
8.3.210.0110.00816.54
8.3.200.0060.00316.77
8.3.190.0100.00918.47
8.3.180.0140.00616.51
8.3.170.0100.00717.23
8.3.160.0120.00616.90
8.3.150.0120.00618.39
8.3.140.0100.01017.34
8.3.130.0080.00818.35
8.3.120.0100.00720.66
8.3.110.0080.00320.94
8.3.100.0050.00324.06
8.3.90.0040.00426.77
8.3.80.0060.00316.65
8.3.70.0140.00716.75
8.3.60.0100.01316.63
8.3.50.0090.01223.02
8.3.40.0140.00718.98
8.3.30.0190.00319.04
8.3.20.0000.00820.16
8.3.10.0040.00421.73
8.3.00.0120.00317.90
8.2.290.0110.00720.43
8.2.280.0060.00918.31
8.2.270.0030.00717.34
8.2.260.0120.00316.89
8.2.250.0120.00616.83
8.2.240.0090.00617.32
8.2.230.0090.00922.58
8.2.220.0100.00737.54
8.2.210.0110.00426.77
8.2.200.0030.00616.88
8.2.190.0090.00616.58
8.2.180.0110.00325.92
8.2.170.0210.00018.96
8.2.160.0140.00022.96
8.2.150.0000.00924.18
8.2.140.0040.00424.66
8.2.130.0070.01426.16
8.2.120.0090.00920.62
8.2.110.0040.00422.21
8.2.100.0070.00417.91
8.2.90.0040.00419.21
8.2.80.0060.00317.97
8.2.70.0030.00617.63
8.2.60.0080.00019.53
8.2.50.0040.00418.07
8.2.40.0040.00420.00
8.2.30.0000.00819.72
8.2.20.0000.01017.72
8.2.10.0050.00517.98
8.2.00.0030.00517.71
8.1.330.0080.01021.85
8.1.320.0140.00416.20
8.1.310.0080.00018.63
8.1.300.0140.00418.00
8.1.290.0070.00430.84
8.1.280.0140.00325.92
8.1.270.0050.00323.99
8.1.260.0040.00426.35
8.1.250.0070.00028.09
8.1.240.0040.00423.99
8.1.230.0030.00819.10
8.1.220.0000.00817.74
8.1.210.0080.00018.77
8.1.200.0060.00317.48
8.1.190.0030.00617.36
8.1.180.0030.00618.10
8.1.170.0000.00818.68
8.1.160.0000.00722.04
8.1.150.0000.00718.93
8.1.140.0040.00417.50
8.1.130.0030.00317.42
8.1.120.0000.00717.48
8.1.110.0080.00017.48
8.1.100.0040.00417.32
8.1.90.0040.00417.41
8.1.80.0000.00817.46
8.1.70.0070.00017.48
8.1.60.0060.00317.52
8.1.50.0040.00417.49
8.1.40.0000.00917.49
8.1.30.0000.00817.72
8.1.20.0000.00917.52
8.1.10.0000.00817.50
8.1.00.0000.01117.62
8.0.300.0040.00420.85
8.0.290.0040.00417.05
8.0.280.0000.00718.48
8.0.270.0000.00717.30
8.0.260.0040.00416.96
8.0.250.0040.00717.07
8.0.240.0030.00317.06
8.0.230.0000.00717.05
8.0.220.0070.00016.90
8.0.210.0060.00316.87
8.0.200.0000.00617.04
8.0.190.0000.00717.06
8.0.180.0000.00716.93
8.0.170.0030.00516.99
8.0.160.0040.00416.93
8.0.150.0000.00716.80
8.0.140.0000.00916.95
8.0.130.0060.00013.41
8.0.120.0040.00417.01
8.0.110.0050.00217.01
8.0.100.0000.00717.02
8.0.90.0030.00617.00
8.0.80.0090.00616.95
8.0.70.0040.00417.01
8.0.60.0000.00716.98
8.0.50.0000.00716.94
8.0.30.0070.01317.01
8.0.20.0090.01117.40
8.0.10.0040.00417.18
8.0.00.0080.01016.86
7.4.330.0000.00715.03
7.4.320.0040.00416.53
7.4.300.0000.00916.63
7.4.290.0000.00616.62
7.4.280.0030.00316.63
7.4.270.0070.00016.56
7.4.260.0000.00716.62
7.4.250.0070.00016.42
7.4.240.0050.00216.56
7.4.230.0070.00016.64
7.4.220.0120.00916.64
7.4.210.0070.00816.69
7.4.200.0000.00716.66
7.4.160.0150.00316.50
7.4.150.0120.00617.40
7.4.140.0130.00617.86
7.4.130.0100.00916.51
7.4.120.0100.00816.58
7.4.110.0130.00716.50
7.4.100.0110.01116.55
7.4.90.0100.00716.47
7.4.80.0140.00319.39
7.4.70.0060.01216.34
7.4.60.0060.01016.52
7.4.50.0030.00316.28
7.4.40.0090.00916.59
7.4.30.0110.00616.55
7.4.00.0080.00915.14
7.3.330.0030.00313.31
7.3.320.0030.00313.26
7.3.310.0000.00716.29
7.3.300.0030.00316.23
7.3.290.0000.00716.30
7.3.280.0110.00616.25
7.3.270.0150.00317.40
7.3.260.0130.00416.28
7.3.250.0140.00616.55
7.3.240.0120.00416.53
7.3.230.0090.01816.39
7.3.210.0100.00716.48
7.3.200.0110.01119.39
7.3.190.0110.01116.33
7.3.180.0060.00916.25
7.3.170.0110.00416.49
7.3.160.0130.01016.67
7.3.120.0060.00914.82
7.3.110.0040.01414.80
7.3.100.0070.00715.01
7.3.90.0060.00614.90
7.3.80.0000.01715.10
7.3.70.0080.00814.86
7.3.60.0000.01714.86
7.3.50.0060.00614.88
7.3.40.0030.01014.70
7.3.30.0030.00914.83
7.3.20.0060.00916.59
7.3.10.0040.01516.69
7.3.00.0040.01416.72
7.2.330.0000.01816.94
7.2.320.0100.01316.80
7.2.310.0090.01416.77
7.2.300.0100.00716.46
7.2.290.0080.00816.79
7.2.250.0080.00815.13
7.2.240.0060.01315.18
7.2.230.0100.00615.19
7.2.220.0060.00615.19
7.2.210.0000.01215.08
7.2.200.0000.01015.15
7.2.190.0140.00414.97
7.2.180.0130.00415.07
7.2.170.0030.01215.05
7.2.60.0130.00316.78
7.2.00.0030.01019.03
7.1.330.0080.00815.70
7.1.320.0060.00615.77
7.1.310.0090.00915.90
7.1.300.0060.00915.70
7.1.290.0130.00415.99
7.1.280.0110.00416.02
7.1.270.0060.00915.75
7.1.260.0110.00315.54
7.1.200.0040.00415.86
7.1.100.0090.00317.99
7.1.70.0000.00817.12
7.1.60.0070.00717.13
7.1.50.0110.01116.82
7.1.00.0030.07722.37
7.0.200.0060.01016.79
7.0.140.0000.06721.98
7.0.60.0070.06720.09
7.0.50.0130.07717.89
7.0.40.0030.05320.23
7.0.30.0330.07720.15
7.0.20.0230.06320.30
7.0.10.0000.04720.23
7.0.00.0070.04020.05
5.6.280.0030.07321.09
5.6.210.0070.04020.75
5.6.200.0100.05318.16
5.6.190.0070.06020.39
5.6.180.0200.04320.39
5.6.170.0330.07020.47
5.6.160.0030.08320.43
5.6.150.0100.07018.22
5.6.140.0030.08718.16
5.6.130.0070.07318.16
5.6.120.0030.07321.05
5.6.110.0030.04321.16
5.6.100.0100.04021.03
5.6.90.0070.07721.15
5.6.80.0100.05020.41
5.5.350.0070.04020.53
5.5.340.0070.06018.02
5.5.330.0000.09020.57
5.5.320.0100.04720.30
5.5.310.0200.05020.27
5.5.300.0030.04318.08
5.5.290.0030.04317.94
5.5.280.0030.08320.90
5.5.270.0130.08320.87
5.5.260.0130.07720.87
5.5.250.0100.04320.58
5.5.240.0170.06020.03
5.4.450.0830.05319.55
5.4.440.1000.06019.59
5.4.430.0200.04319.63
5.4.420.0030.06319.51
5.4.410.0030.06019.08
5.4.400.0100.05018.53
5.4.390.0170.05018.59
5.4.380.0170.05318.54
5.4.370.0030.04018.76
5.4.360.0030.03718.78
5.4.350.0100.04018.76
5.4.340.0030.04318.56
5.4.320.0070.04018.44
5.4.310.0070.03718.39
5.4.300.0000.04318.80
5.4.290.0170.04318.44
5.4.280.0100.05018.47
5.4.270.0100.04718.57
5.4.260.0030.04718.75
5.4.250.0130.03318.49
5.4.240.0070.04018.71
5.4.230.0100.03318.55
5.4.220.0070.04018.76
5.4.210.0030.04318.55
5.4.200.0030.04016.71
5.4.190.0070.03718.74
5.4.180.0100.03318.64
5.4.170.0000.04718.55
5.4.160.0070.04718.48
5.4.150.0170.03018.54
5.4.140.0070.04016.28
5.4.130.0100.04716.28
5.4.120.0070.03716.29
5.4.110.0000.04016.28
5.4.100.0100.03316.46
5.4.90.0100.03316.35
5.4.80.0130.03316.25
5.4.70.0070.04016.35
5.4.60.0030.04016.23
5.4.50.0070.03716.29
5.4.40.0100.03716.23
5.4.30.0070.03716.14
5.4.20.0070.03716.14
5.4.10.0030.05316.25
5.4.00.0070.03715.90
5.3.290.0030.04314.73
5.3.280.0070.03714.55
5.3.270.0070.04014.54
5.3.260.0070.04014.64
5.3.250.0030.04314.65
5.3.240.0100.03714.69
5.3.230.0070.04014.78
5.3.220.0100.03714.61
5.3.210.0100.04014.56
5.3.200.0130.03314.56
5.3.190.0130.03314.51
5.3.180.0030.04314.55
5.3.170.0130.04714.56
5.3.160.0200.04014.54
5.3.150.0100.04014.71
5.3.140.0100.04014.52
5.3.130.0230.04014.58
5.3.120.0070.04014.73
5.3.110.0130.03314.71
5.3.100.0000.04714.14
5.3.90.0100.03714.04
5.3.80.0100.03714.06
5.3.70.0070.03713.99
5.3.60.0170.02713.99
5.3.50.0070.03714.02
5.3.40.0070.03713.92
5.3.30.0000.04314.02
5.3.20.0070.03713.63
5.3.10.0070.03713.59
5.3.00.0070.03713.71
5.2.170.0070.03011.20
5.2.160.0130.02011.12
5.2.150.0030.04011.20
5.2.140.0170.02711.23
5.2.130.0000.03311.15
5.2.120.0070.03311.03
5.2.110.0070.02711.06
5.2.100.0000.03311.02
5.2.90.0030.03011.15
5.2.80.0030.03311.17
5.2.70.0100.02711.02
5.2.60.0000.03710.98
5.2.50.0030.03310.99
5.2.40.0000.03311.01
5.2.30.0100.02711.02
5.2.20.0030.03310.93
5.2.10.0030.03010.86
5.2.00.0030.03310.80
5.1.60.0030.0239.95
5.1.50.0070.0279.95
5.1.40.0070.0239.90
5.1.30.0030.02710.36
5.1.20.0030.02710.33
5.1.10.0100.02010.11
5.1.00.0030.02710.05
5.0.50.0030.0208.57
5.0.40.0070.0178.43
5.0.30.0030.0338.23
5.0.20.0030.0208.23
5.0.10.0030.0208.30
5.0.00.0070.0278.12
4.4.90.0000.0175.86
4.4.80.0030.0135.82
4.4.70.0000.0175.83
4.4.60.0000.0175.92
4.4.50.0130.0175.83
4.4.40.0000.0275.76
4.4.30.0000.0175.81
4.4.20.0030.0135.82
4.4.10.0070.0105.91
4.4.00.0030.0235.88
4.3.110.0000.0175.77
4.3.100.0000.0175.75
4.3.90.0000.0175.79
4.3.80.0030.0235.77
4.3.70.0100.0105.90
4.3.60.0000.0175.90
4.3.50.0030.0175.75
4.3.40.0030.0305.72
4.3.30.0030.0174.57
4.3.20.0000.0204.53
4.3.10.0030.0134.46
4.3.00.0130.0236.76

preferences:
30.89 ms | 403 KiB | 5 Q