3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface IWidget { } class WidgetA implements IWidget { } class WidgetB implements IWidget { } interface IWidgetFactory { function tryCreateWidget($someInput, IWidget &$widget = null); } class WidgetAFactory implements IWidgetFactory { public function tryCreateWidget($someInput, IWidget &$widget = null) { if ($someInput < 7) { $widget = new WidgetA(); return true; } return false; } } class WidgetBFactory implements IWidgetFactory { public function tryCreateWidget($someInput, IWidget &$widget = null) { if ($someInput > 10) { $widget = new WidgetB(); return true; } return false; } } class WidgetFactoryAggregate implements IWidgetFactory { private $widgetFactories = []; function __construct(array $widgetFactories) { $this->widgetFactories = $widgetFactories; } public function tryCreateWidget($someInput, IWidget &$widget = null) { foreach ($this->widgetFactories as $widgetFactory) { if ($widgetFactory->tryCreateWidget($someInput)) { return true; } } return false; } } $widgetFactory = new WidgetFactoryAggregate([ new WidgetAFactory(), new WidgetBFactory(), ]); foreach ([1, 5, 15, 9] as $someInput) { $widget = null; if ($widgetFactory->tryCreateWidget($someInput, $widget)) { var_dump($widget); continue; } var_dump("Failed to create widget for {$someInput}"); break; }

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.00716.48
8.3.60.0120.00316.63
8.3.50.0110.01122.00
8.3.40.0150.00018.67
8.3.30.0030.01019.21
8.3.20.0070.00020.39
8.3.10.0080.00023.48
8.3.00.0040.00422.57
8.2.190.0040.01116.68
8.2.180.0140.01016.75
8.2.170.0040.01122.96
8.2.160.0160.00322.10
8.2.150.0080.00024.18
8.2.140.0050.00324.66
8.2.130.0080.00026.16
8.2.120.0040.00422.08
8.2.110.0030.00622.01
8.2.100.0000.01217.84
8.2.90.0030.00619.17
8.2.80.0050.00317.97
8.2.70.0060.00317.36
8.2.60.0000.00817.93
8.2.50.0000.00818.07
8.2.40.0000.00819.39
8.2.30.0040.00418.09
8.2.20.0050.00317.76
8.2.10.0030.00519.40
8.2.00.0000.00717.85
8.1.280.0090.00625.92
8.1.270.0000.00922.07
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0060.00320.90
8.1.230.0040.00719.21
8.1.220.0030.00617.75
8.1.210.0000.00818.77
8.1.200.0060.00317.48
8.1.190.0080.00017.53
8.1.180.0080.00018.10
8.1.170.0000.00818.52
8.1.160.0040.00421.98
8.1.150.0000.00818.68
8.1.140.0030.00617.54
8.1.130.0050.00317.88
8.1.120.0040.00417.48
8.1.110.0030.00517.34
8.1.100.0050.00317.51
8.1.90.0000.00717.53
8.1.80.0000.00817.38
8.1.70.0030.00317.44
8.1.60.0000.00817.65
8.1.50.0030.00617.49
8.1.40.0090.00017.56
8.1.30.0000.00817.52
8.1.20.0000.00817.72
8.1.10.0000.00817.62
8.1.00.0040.00417.55
8.0.300.0000.00718.77
8.0.290.0000.00717.02
8.0.280.0070.00018.39
8.0.270.0030.00317.23
8.0.260.0000.00816.91
8.0.250.0030.00317.04
8.0.240.0030.00317.00
8.0.230.0030.00316.90
8.0.220.0030.00316.94
8.0.210.0040.00417.00
8.0.200.0030.00316.89
8.0.190.0000.00717.01
8.0.180.0070.00016.93
8.0.170.0040.00417.00
8.0.160.0080.00016.88
8.0.150.0080.00016.73
8.0.140.0050.00316.86
8.0.130.0000.00613.40
8.0.120.0050.00317.01
8.0.110.0050.00316.96
8.0.100.0000.00816.73
8.0.90.0050.00216.88
8.0.80.0120.00316.97
8.0.70.0040.00416.96
8.0.60.0000.00716.87
8.0.50.0030.00517.00
8.0.30.0080.01416.90
8.0.20.0080.01417.40
8.0.10.0040.00417.09
8.0.00.0090.00816.68
7.4.330.0050.00015.02
7.4.320.0060.00016.45
7.4.300.0030.00316.54
7.4.290.0030.00316.57
7.4.280.0000.00816.63
7.4.270.0030.00316.55
7.4.260.0040.00416.55
7.4.250.0050.00316.50
7.4.240.0040.00416.57
7.4.230.0070.00016.63
7.4.220.0090.00916.61
7.4.210.0080.01016.58
7.4.200.0040.00416.52
7.4.190.0070.00016.80
7.4.160.0070.01116.40
7.4.150.0130.00417.40
7.4.140.0120.00717.86
7.4.130.0090.00816.52
7.4.120.0100.00816.63
7.4.110.0030.01516.52
7.4.100.0090.00616.50
7.4.90.0150.00316.59
7.4.80.0130.01016.52
7.4.70.0140.00316.56
7.4.60.0080.01116.44
7.4.50.0000.00616.29
7.4.40.0110.00722.77
7.4.30.0060.00916.63
7.4.00.0090.00614.68
7.3.330.0030.00313.41
7.3.320.0030.00313.31
7.3.310.0000.00716.37
7.3.300.0000.00716.39
7.3.290.0090.00616.39
7.3.280.0080.00916.34
7.3.270.0120.00417.40
7.3.260.0090.00916.50
7.3.250.0080.01016.38
7.3.240.0130.00316.40
7.3.230.0090.00916.40
7.3.210.0060.01316.33
7.3.200.0060.01219.39
7.3.190.0160.00616.55
7.3.180.0110.00416.30
7.3.170.0070.01016.57
7.3.160.0120.00816.58
7.3.120.0040.01114.63
7.2.330.0120.00916.54
7.2.320.0110.00816.84
7.2.310.0050.01116.69
7.2.300.0190.00616.80
7.2.290.0130.00616.83
7.2.60.0030.01316.79
7.1.200.0070.00315.73
7.1.70.0000.00817.29
7.1.60.0150.00619.29
7.1.50.0100.01416.75
7.1.00.0000.08022.32
7.0.200.0120.00316.81
7.0.140.0000.07722.13
7.0.60.0070.07320.06
7.0.50.0100.03317.91
7.0.40.0000.09320.20
7.0.30.0230.03720.23
7.0.20.0230.05020.05
7.0.10.0270.07720.23
7.0.00.0030.04020.25
5.6.280.0100.07021.12
5.6.210.0070.08020.70
5.6.200.0100.08018.24
5.6.190.0030.04720.57
5.6.180.0230.05020.46
5.6.170.0330.07020.53
5.6.160.0170.07320.61
5.6.150.0100.08018.13
5.6.140.0070.08018.18
5.6.130.0070.05318.15
5.6.120.0070.08721.02
5.6.110.0100.08321.13
5.6.100.0030.08021.05
5.6.90.0030.08721.12
5.6.80.0170.06720.46
5.6.70.0270.07720.39
5.5.350.2730.04020.46
5.5.340.0030.06017.99
5.5.330.0030.05020.47
5.5.320.0130.07320.43
5.5.310.0300.07020.27
5.5.300.0030.05318.04
5.5.290.0030.07318.02
5.5.280.0100.04020.71
5.5.270.0100.03720.78
5.5.260.0100.08320.80
5.5.250.0100.07320.48
5.5.240.0130.07020.09
5.4.450.0700.06019.59
5.4.440.1130.07719.47
5.4.430.1030.06719.60
5.4.420.0870.07319.47
5.4.410.0900.06719.34
5.4.400.0170.07018.67
5.4.390.0170.06718.81
5.4.380.0300.04718.55
5.4.370.0030.06018.66
5.4.360.0100.04718.63
5.4.350.0070.03312.04
5.4.340.0040.03612.03
5.4.320.0170.03212.52
5.4.310.0040.03912.52
5.4.300.0060.04012.52
5.4.290.0100.04312.52
5.4.280.0050.05012.39
5.4.270.0090.04612.38
5.4.260.0110.04812.38
5.4.250.0100.05212.38
5.4.240.0120.04812.38
5.4.230.0060.05412.38
5.4.220.0090.04912.37
5.4.210.0090.04812.37
5.4.200.0110.04712.38
5.4.190.0050.05212.37
5.4.180.0080.04912.37
5.4.170.0060.05012.38
5.4.160.0070.04712.38
5.4.150.0060.04912.38
5.4.140.0100.05312.05
5.4.130.0090.04512.05
5.4.120.0040.05312.00
5.4.110.0090.04412.00
5.4.100.0130.04112.00
5.4.90.0090.06112.00
5.4.80.0070.05312.00
5.4.70.0080.05312.00
5.4.60.0050.05411.99
5.4.50.0080.04511.99
5.4.40.0080.05011.98
5.4.30.0070.05011.98
5.4.20.0080.05111.98
5.4.10.0110.05211.98
5.4.00.0050.04111.46
5.3.290.0040.04712.80
5.3.280.0080.04112.71
5.3.270.0090.03912.72
5.3.260.0110.04712.71
5.3.250.0080.04612.71
5.3.240.0040.04912.71
5.3.230.0060.04012.71
5.3.220.0110.03712.68
5.3.210.0070.04612.68
5.3.200.0100.05012.68
5.3.190.0100.04712.68
5.3.180.0070.04612.67
5.3.170.0120.04012.67
5.3.160.0090.04112.67
5.3.150.0100.04212.67
5.3.140.0080.04412.66
5.3.130.0070.04112.66
5.3.120.0100.04812.66
5.3.110.0120.05812.66
5.3.100.0050.04112.12
5.3.90.0050.04412.09
5.3.80.0070.04012.09
5.3.70.0080.03812.08
5.3.60.0070.05012.06
5.3.50.0090.04112.01
5.3.40.0070.04912.01
5.3.30.0070.04611.96
5.3.20.0100.04311.75
5.3.10.0080.03511.71
5.3.00.0100.03811.71
5.2.170.0050.0349.21
5.2.160.0080.0329.20
5.2.150.0050.0329.21
5.2.140.0060.0309.20
5.2.130.0040.0309.16
5.2.120.0080.0289.16
5.2.110.0040.0329.16
5.2.100.0030.0329.16
5.2.90.0020.0349.16
5.2.80.0040.0329.16
5.2.70.0050.0359.16
5.2.60.0060.0419.11
5.2.50.0090.0469.09
5.2.40.0050.0439.05
5.2.30.0070.0359.04
5.2.20.0050.0409.02
5.2.10.0060.0298.93
5.2.00.0040.0318.80
5.1.60.0110.0378.09
5.1.50.0080.0338.09
5.1.40.0060.0268.07
5.1.30.0070.0258.41
5.1.20.0050.0278.43
5.1.10.0040.0288.16
5.1.00.0060.0278.16
5.0.50.0060.0196.64
5.0.40.0050.0196.50
5.0.30.0020.0336.30
5.0.20.0040.0196.27
5.0.10.0050.0276.25
5.0.00.0050.0296.24
4.4.90.0090.0184.78
4.4.80.0050.0214.76
4.4.70.0040.0154.76
4.4.60.0020.0164.75
4.4.50.0030.0154.77
4.4.40.0030.0254.70
4.4.30.0050.0134.76
4.4.20.0030.0154.84
4.4.10.0040.0144.85
4.4.00.0020.0254.76
4.3.110.0030.0154.66
4.3.100.0010.0184.66
4.3.90.0050.0194.63
4.3.80.0050.0314.58
4.3.70.0050.0194.63
4.3.60.0040.0204.63
4.3.50.0040.0214.63
4.3.40.0020.0314.54
4.3.30.0000.0193.27
4.3.20.0020.0163.25
4.3.10.0030.0163.21
4.3.00.0100.0237.14

preferences:
44.62 ms | 401 KiB | 5 Q