3v4l.org

run code in 300+ PHP versions simultaneously
<?php //my variante final class StateOptions { public function __construct(array $options) { $this->options = $options; } private function validate() { if ($this->options === []) { return false; } return true; } public function getNextState() { return $this->options['nextState'] ?? 'defaultstate'; } } class BusinessLogicServiceOOp { public function changeState(StateOptions $stateOptions) { $this->changeTo($stateOptions->getNextState()); } public function changeTo(string $changeTo) { echo $changeTo; } } //array solution class BusinessLogicServiceLegacy { public function changeState(array $stateOptions) { /** Problem here is, that no validation ran on mandatory or optional flags or on valid flags from business perspective**/ $this->changeTo($stateOptions['nextState'] ?? 'defaultstate'); } public function changeTo(string $changeTo) { echo $changeTo; } } (new BusinessLogicServiceLegacy())->changeState([]); (new BusinessLogicServiceOOp())->changeState(new StateOptions([]));

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.140.0130.00917.91
8.4.130.0060.00319.35
8.4.120.0100.01120.46
8.4.110.0140.00718.98
8.4.100.0100.00718.97
8.4.90.0070.00620.58
8.4.80.0060.00319.15
8.4.70.0120.00819.11
8.4.60.0110.00918.75
8.4.50.0080.01218.73
8.4.40.0060.01317.76
8.4.30.0160.00320.68
8.4.20.0100.01017.98
8.4.10.0040.00419.75
8.3.270.0110.00816.80
8.3.260.0090.00916.64
8.3.250.0100.01017.13
8.3.240.0040.00516.79
8.3.230.0030.00516.59
8.3.220.0090.00818.86
8.3.210.0140.00916.79
8.3.200.0030.00516.71
8.3.190.0120.00817.10
8.3.180.0110.00718.92
8.3.170.0060.01316.77
8.3.160.0140.00319.04
8.3.150.0100.00619.05
8.3.140.0150.00020.92
8.3.130.0080.00018.31
8.3.120.0030.00618.90
8.3.110.0090.00020.94
8.3.100.0030.00724.06
8.3.90.0040.01126.77
8.3.80.0090.00019.36
8.3.70.0120.00316.58
8.3.60.0070.01416.73
8.3.50.0090.00923.66
8.3.40.0170.00318.82
8.3.30.0040.01118.84
8.3.20.0040.00424.18
8.3.10.0000.00724.66
8.3.00.0080.00026.16
8.2.290.0110.00919.20
8.2.280.0110.00920.19
8.2.270.0110.00716.93
8.2.260.0150.00316.82
8.2.250.0050.00317.05
8.2.240.0040.00417.49
8.2.230.0040.00422.58
8.2.220.0090.00037.54
8.2.210.0000.00826.77
8.2.200.0040.00418.88
8.2.190.0120.00316.68
8.2.180.0140.00425.92
8.2.170.0110.00719.08
8.2.160.0100.00322.96
8.2.150.0120.00325.66
8.2.140.0050.00324.66
8.2.130.0070.00026.16
8.2.120.0000.00826.35
8.2.110.0000.01022.20
8.2.100.0040.00717.84
8.2.90.0090.00017.88
8.2.80.0000.00918.71
8.2.70.0060.00318.01
8.2.60.0050.00518.34
8.2.50.0060.00318.10
8.2.40.0040.00421.07
8.2.30.0070.00019.38
8.2.20.0050.00218.19
8.2.10.0000.00719.23
8.2.00.0040.00419.32
8.1.330.0060.00616.07
8.1.320.0080.01217.90
8.1.310.0060.00916.39
8.1.300.0150.00416.08
8.1.290.0060.00330.84
8.1.280.0070.01125.92
8.1.270.0130.00623.73
8.1.260.0050.00328.09
8.1.250.0040.00428.09
8.1.240.0060.00324.02
8.1.230.0120.00319.04
8.1.220.0030.00617.74
8.1.210.0050.00318.77
8.1.200.0060.00317.23
8.1.190.0000.00817.10
8.1.180.0030.00618.10
8.1.170.0090.00018.66
8.1.160.0070.00018.94
8.1.150.0000.00818.85
8.1.140.0040.00418.71
8.1.130.0070.00020.01
8.1.120.0070.00017.39
8.1.110.0070.00017.23
8.1.100.0000.00717.32
8.1.90.0080.00017.45
8.1.80.0050.00517.32
8.1.70.0030.00317.34
8.1.60.0060.00317.51
8.1.50.0000.00717.61
8.1.40.0000.00817.46
8.1.30.0060.00317.64
8.1.20.0050.00317.68
8.1.10.0000.00817.57
8.1.00.0000.00817.57
8.0.300.0040.00419.63
8.0.290.0090.00016.63
8.0.280.0000.00718.46
8.0.270.0000.00716.86
8.0.260.0050.00218.59
8.0.250.0000.00717.01
8.0.240.0050.00317.04
8.0.230.0000.00716.78
8.0.220.0020.00516.70
8.0.210.0040.00416.91
8.0.200.0070.00016.92
8.0.190.0040.00416.95
8.0.180.0060.00316.90
8.0.170.0050.00616.75
8.0.160.0000.00716.97
8.0.150.0050.00216.82
8.0.140.0000.00816.72
8.0.130.0030.00313.23
8.0.120.0040.00416.77
8.0.110.0050.00316.77
8.0.100.0040.00416.72
8.0.90.0000.00716.92
8.0.80.0090.00616.88
8.0.70.0050.00316.98
8.0.60.0040.00416.88
8.0.50.0080.00016.91
8.0.30.0060.01117.02
8.0.20.0130.00617.00
8.0.10.0040.00416.87
8.0.00.0120.00616.72
7.4.330.0050.00015.55
7.4.320.0030.00316.57
7.4.300.0030.00316.53
7.4.290.0030.00316.39
7.4.280.0030.00516.41
7.4.270.0040.00416.56
7.4.260.0000.00613.25
7.4.250.0070.00016.32
7.4.240.0060.00316.58
7.4.230.0040.00416.38
7.4.220.0020.00516.52
7.4.210.0070.00716.46
7.4.200.0000.00716.35
7.4.130.0160.00316.33
7.4.120.0120.00616.47
7.4.110.0230.00016.50
7.4.100.0090.00916.39
7.4.90.0070.01016.18
7.4.80.0140.00316.64
7.4.70.0030.01316.31
7.4.60.0060.01216.33
7.4.50.0030.01516.57
7.4.40.0110.00716.64
7.4.30.0090.00916.32
7.4.20.0090.00916.48
7.4.10.0080.00816.35
7.4.00.0140.00416.53
7.3.330.0000.00616.35
7.3.320.0000.00513.16
7.3.310.0000.00716.23
7.3.300.0080.00016.35
7.3.290.0070.00916.32
7.3.260.0060.01616.55
7.3.250.0090.00916.25
7.3.240.0130.00416.54
7.3.230.0090.00916.27
7.3.220.0070.01016.71
7.3.210.0030.01516.22
7.3.200.0060.01016.21
7.3.190.0130.00416.14
7.3.180.0040.01316.28
7.3.170.0080.00816.36
7.3.160.0060.01116.33
7.3.150.0100.00716.60
7.3.140.0100.00716.48
7.3.130.0100.01016.46
7.3.120.0140.00416.61
7.3.110.0110.00716.35
7.3.100.0130.00716.48
7.3.90.0140.00416.56
7.3.80.0070.01116.48
7.3.70.0090.00916.52
7.3.60.0140.00416.33
7.3.50.0100.00716.50
7.3.40.0080.00916.44
7.3.30.0030.01316.31
7.3.20.0100.01116.39
7.3.10.0180.00016.26
7.3.00.0070.01416.55

preferences:
84.07 ms | 403 KiB | 5 Q