3v4l.org

run code in 300+ PHP versions simultaneously
<?php class AssemblyFactory { public const PUMPMETHODS = [ 'modelNumber' => 'fromModelNumber', 'productId' => 'fromProductId' ]; public $pumpFactory; public function __construct () { $this->pumpFactory = new PumpFactory(); } public function makeAssembly(array $params) { $validMethods = array_intersect_key(self::PUMPMETHODS, $params); if (!$validMethods) { throw new \InvalidArgumentException("FAIL"); } else { foreach ($validMethods as $paramKey => $methodName) { return $this->pumpFactory->{$methodName}($params[$paramKey]); } } } } class PumpFactory { public function fromProductId($id) { return "__{$id}__"; } public function fromModelNumber($id) { return "**{$id}**"; } } $factory = new AssemblyFactory(); $tests = [ ['productId' => 33], ['modelNumber' => 'AAA-50'], ['productId' => 1, 'modelNumber' => 'BBB-01'], ['invalidKey' => 'nope'] ]; foreach ($tests as $testParams) { $factory = new AssemblyFactory; echo "Pump = " , $factory->makeAssembly($testParams), "\n"; }

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.00817.98
8.4.130.0150.00819.48
8.4.120.0090.00922.05
8.4.110.0130.00920.70
8.4.100.0100.01017.87
8.4.90.0110.01018.86
8.4.80.0130.00419.93
8.4.70.0090.01218.93
8.4.60.0100.00919.05
8.4.50.0040.00518.75
8.4.40.0040.00420.51
8.4.30.0120.00324.53
8.4.20.0100.01018.89
8.4.10.0000.00917.79
8.3.270.0090.01016.82
8.3.260.0080.01116.73
8.3.250.0150.00417.11
8.3.240.0070.00916.86
8.3.230.0100.00916.88
8.3.220.0050.00417.11
8.3.210.0090.00618.78
8.3.200.0040.00416.94
8.3.190.0120.00717.04
8.3.180.0040.00518.58
8.3.170.0060.01218.90
8.3.160.0130.00617.07
8.3.150.0120.00617.25
8.3.140.0040.00416.79
8.3.130.0070.01118.42
8.3.120.0070.00420.84
8.3.110.0060.00316.66
8.3.100.0030.00616.94
8.3.90.0060.00926.77
8.3.80.0030.00616.63
8.3.70.0110.01116.63
8.3.60.0070.01118.68
8.3.50.0100.00821.08
8.3.40.0090.01318.93
8.3.30.0080.00618.89
8.3.20.0040.00421.89
8.3.10.0050.00320.07
8.3.00.0060.00323.66
8.2.290.0090.01020.46
8.2.280.0110.00818.49
8.2.270.0060.01220.73
8.2.260.0060.00316.83
8.2.250.0040.00416.75
8.2.240.0090.00917.15
8.2.230.0040.00420.94
8.2.220.0060.00324.06
8.2.210.0070.00726.77
8.2.200.0030.00616.88
8.2.190.0130.00616.63
8.2.180.0090.00918.54
8.2.170.0140.00422.96
8.2.160.0040.01119.46
8.2.150.0050.00524.18
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0080.00026.16
8.2.110.0090.00021.18
8.2.100.0040.00817.97
8.2.90.0030.00518.06
8.2.80.0080.00017.97
8.2.70.0110.00017.68
8.2.60.0030.00618.34
8.2.50.0030.00518.10
8.2.40.0080.00019.47
8.2.30.0050.00319.43
8.2.20.0040.00418.16
8.2.10.0040.00421.19
8.2.00.0000.00819.30
8.1.330.0080.01222.09
8.1.320.0070.01118.04
8.1.310.0120.00621.63
8.1.300.0040.00419.82
8.1.290.0050.00530.84
8.1.280.0070.00725.92
8.1.270.0070.00722.24
8.1.260.0050.00226.35
8.1.250.0040.00428.09
8.1.240.0040.00423.83
8.1.230.0150.00020.66
8.1.220.0030.00617.74
8.1.210.0040.00418.77
8.1.200.0030.00617.35
8.1.190.0000.00817.36
8.1.180.0040.00418.10
8.1.170.0050.00318.61
8.1.160.0000.00718.91
8.1.150.0000.00718.96
8.1.140.0000.00723.80
8.1.130.0030.00320.19
8.1.120.0000.00717.47
8.1.110.0090.00017.46
8.1.100.0000.00717.38
8.1.90.0000.00917.52
8.1.80.0030.00517.39
8.1.70.0000.00817.43
8.1.60.0060.00317.61
8.1.50.0040.00417.42
8.1.40.0000.00817.42
8.1.30.0030.00617.59
8.1.20.0000.00817.50
8.1.10.0040.00417.50
8.1.00.0000.00717.54
8.0.300.0030.00519.65
8.0.290.0000.00716.88
8.0.280.0030.00318.46
8.0.270.0070.00017.16
8.0.260.0000.00821.68
8.0.250.0000.00916.98
8.0.240.0070.00017.04
8.0.230.0060.00316.90
8.0.220.0000.00817.01
8.0.210.0000.00716.84
8.0.200.0000.00717.04
8.0.190.0050.00317.07
8.0.180.0040.00816.89
8.0.170.0030.00516.91
8.0.160.0050.00316.88
8.0.150.0000.00716.86
8.0.140.0040.00416.92
8.0.130.0000.00613.39
8.0.120.0020.00516.91
8.0.110.0070.00016.88
8.0.100.0040.00416.80
8.0.90.0050.00516.85
8.0.80.0020.01616.88
8.0.70.0000.00817.00
8.0.60.0040.00416.92
8.0.50.0000.00816.86
8.0.30.0130.00717.35
8.0.20.0180.00917.28
8.0.10.0030.00517.13
8.0.00.0130.00516.89
7.4.330.0030.00315.55
7.4.320.0070.00016.59
7.4.300.0090.00016.43
7.4.290.0030.00316.60
7.4.280.0030.00516.60
7.4.270.0040.00416.44
7.4.260.0070.00016.54
7.4.250.0040.00416.59
7.4.240.0040.00416.51
7.4.230.0000.00716.70
7.4.220.0000.00816.64
7.4.210.0040.01016.58
7.4.200.0000.00716.64
7.4.130.0100.01016.66
7.4.120.0040.01316.45
7.4.110.0070.01016.53
7.4.100.0100.01316.34
7.4.90.0130.00316.77
7.4.80.0120.00919.39
7.4.70.0000.01616.48
7.4.60.0090.00616.51
7.4.50.0100.00716.55
7.4.40.0110.00516.61
7.4.00.0070.00714.56
7.3.330.0030.00313.41
7.3.320.0030.00313.51
7.3.310.0070.00016.42
7.3.300.0060.00016.48
7.3.290.0080.00516.43
7.3.280.0180.00316.44
7.3.260.0100.00816.45
7.3.240.0120.00716.57
7.3.230.0120.00916.70
7.3.210.0040.01416.50
7.3.200.0070.01016.44
7.3.190.0040.01616.46
7.3.180.0110.00616.63
7.3.170.0090.00616.54
7.3.160.0120.00816.57
7.3.70.0100.01314.59
7.3.60.0150.00614.89
7.3.50.0100.00314.90
7.3.40.0100.00314.35
7.3.30.0090.00914.83
7.3.20.0180.00914.43
7.3.10.0090.00614.49
7.3.00.0170.00614.53
7.2.330.0130.01016.49
7.2.320.0110.00616.68
7.2.310.0100.00716.66
7.2.300.0150.00416.42
7.2.290.0110.01116.66
7.2.200.0040.01715.15
7.2.190.0070.00715.19
7.2.180.0100.00315.15
7.2.170.0040.01214.92
7.2.160.0060.00915.02
7.2.150.0090.00514.94
7.2.140.0580.00315.02
7.2.130.0190.00615.17
7.2.120.0140.00614.91
7.2.110.0150.00415.36
7.2.100.0070.01115.10
7.2.90.0070.01015.33
7.2.80.0120.00814.88
7.2.70.0160.01015.23
7.2.60.0120.00615.23
7.2.50.0210.00014.91
7.2.40.0140.00315.22
7.2.30.0090.00815.00
7.2.20.0090.00915.25
7.2.10.0110.01415.03
7.2.00.0090.00615.13
7.1.300.0060.00914.15
7.1.290.0090.00614.06
7.1.280.0040.01113.73
7.1.270.0110.01113.72
7.1.260.0100.00614.08
7.1.250.0100.01014.01

preferences:
30.86 ms | 403 KiB | 5 Q