3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait ImmutableFromParams { private $mutable = true; private function __construct(array $params) { foreach ($params as $key => $value) { $this->{'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)))}($value); } unset($this->mutable); } public static function fromParams(array $params) { return new static($params); } public function __call($method, $args) { if (isset($this->mutable) && substr($method, 0, 3) == 'set' && property_exists($this, lcfirst(substr($method, 3)))) { $this->{lcfirst(substr($method, 3))} = reset($args); } } } interface DataTransferObjectInterface { public static function fromParams(array $params); public function asArray(); } abstract class AbstractDataTransferObject implements DataTransferObjectInterface { use ImmutableFromParams; public function asArray() { return get_object_vars($this); } } final class MyDataTransferObject extends AbstractDataTransferObject { protected $foo; protected $bar; protected function setBar($value) { $this->bar = $value; } } $foo = MyDataTransferObject::fromParams(array('foo' => 'foo', 'bar' => 'bar', 'meh' => 'meh')); $foo->setFoo('newfoo'); $foo->setDog('dog'); var_dump($foo->asArray()); interface ValueObjectInterface { public static function fromParams(array $params); public function __toString(); } abstract class AbstractValueObject implements ValueObjectInterface { use ImmutableFromParams; abstract public function __toString(); } final class MyValueObject extends AbstractValueObject { protected $bar; protected function setBar($value) { $this->bar = $value; } public function __toString() { return (string) $bar; } } $foo = MyValueObject::fromParams(array('foo' => 'foo', 'bar' => 'bar', 'meh' => 'meh')); $foo->setFoo('newfoo'); $foo->setDog('dog'); echo $foo;

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.60.0150.00318.81
8.3.50.0120.00616.34
8.3.40.0160.00618.96
8.3.30.0170.00019.22
8.3.20.0150.00420.34
8.3.10.0040.00423.52
8.3.00.0040.00419.38
8.2.180.0150.00317.00
8.2.170.0090.00922.96
8.2.160.0130.00320.53
8.2.150.0080.00024.18
8.2.140.0040.00424.66
8.2.130.0040.00426.16
8.2.120.0040.00720.32
8.2.110.0030.00620.35
8.2.100.0000.01218.16
8.2.90.0040.00419.23
8.2.80.0040.00417.97
8.2.70.0040.00417.75
8.2.60.0040.00718.04
8.2.50.0050.00318.07
8.2.40.0080.00020.00
8.2.30.0040.00418.09
8.2.20.0040.00417.86
8.2.10.0040.00418.00
8.2.00.0000.00817.72
8.1.280.0180.00425.92
8.1.270.0090.00022.32
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0030.00623.82
8.1.230.0080.00419.27
8.1.220.0060.00317.91
8.1.210.0040.00418.77
8.1.200.0060.00317.48
8.1.190.0000.00817.13
8.1.180.0040.00418.10
8.1.170.0000.00918.57
8.1.160.0040.00422.07
8.1.150.0000.00718.99
8.1.140.0050.00217.52
8.1.130.0000.00717.81
8.1.120.0040.00417.44
8.1.110.0050.00317.46
8.1.100.0030.00517.57
8.1.90.0000.00717.48
8.1.80.0020.00517.58
8.1.70.0030.00317.48
8.1.60.0040.00417.70
8.1.50.0000.00817.57
8.1.40.0030.00617.64
8.1.30.0030.00617.68
8.1.20.0080.00017.64
8.1.10.0080.00017.63
8.1.00.0000.00917.50
8.0.300.0070.00018.77
8.0.290.0000.00716.88
8.0.280.0030.00318.41
8.0.270.0000.00717.36
8.0.260.0030.00317.37
8.0.250.0000.00817.04
8.0.240.0060.00317.09
8.0.230.0000.00716.93
8.0.220.0000.00716.88
8.0.210.0000.00717.09
8.0.200.0000.00616.97
8.0.190.0000.00817.06
8.0.180.0030.00516.95
8.0.170.0000.00816.90
8.0.160.0030.00917.04
8.0.150.0000.00816.90
8.0.140.0030.00616.85
8.0.130.0030.00313.41
8.0.120.0080.00016.95
8.0.110.0030.00617.06
8.0.100.0000.00717.13
8.0.90.0020.00516.84
8.0.80.0110.01316.98
8.0.70.0040.00416.88
8.0.60.0050.00316.84
8.0.50.0040.00417.05
8.0.30.0180.00217.04
8.0.20.0130.00517.40
8.0.10.0040.00417.13
8.0.00.0070.01216.70
7.4.330.0050.00015.09
7.4.320.0000.00616.58
7.4.300.0030.00316.46
7.4.290.0050.00216.55
7.4.280.0000.00816.56
7.4.270.0030.00316.63
7.4.260.0040.00416.58
7.4.250.0050.00316.68
7.4.240.0000.00716.69
7.4.230.0000.00816.64
7.4.220.0000.02016.78
7.4.210.0040.01016.53
7.4.200.0040.00416.41
7.4.160.0100.00616.39
7.4.150.0060.01217.40
7.4.140.0110.01017.86
7.4.130.0080.01216.62
7.4.120.0090.00816.74
7.4.110.0140.00616.53
7.4.100.0120.00616.72
7.4.90.0060.01216.50
7.4.80.0050.01419.39
7.4.70.0120.00616.52
7.4.60.0090.00616.56
7.4.50.0040.00416.30
7.4.40.0140.00316.77
7.4.30.0100.00716.69
7.4.00.0100.00715.25
7.3.330.0000.00513.36
7.3.320.0030.00313.34
7.3.310.0050.00216.26
7.3.300.0030.00316.42
7.3.290.0050.01016.32
7.3.280.0080.00716.43
7.3.270.0090.01017.40
7.3.260.0150.01016.46
7.3.250.0090.00916.41
7.3.240.0140.00416.41
7.3.230.0030.01316.41
7.3.210.0030.01316.71
7.3.200.0070.01419.39
7.3.190.0090.01516.52
7.3.180.0060.00916.39
7.3.170.0150.00616.55
7.3.160.0070.01616.47
7.2.330.0130.00616.60
7.2.320.0140.00316.73
7.2.310.0110.00616.81
7.2.300.0140.00316.57
7.2.290.0090.00916.66
7.2.60.0000.01416.81
7.2.00.0000.01119.32
7.1.200.0240.00515.48
7.1.100.0080.00818.23
7.1.70.0070.00016.93
7.1.60.0170.00719.11
7.1.50.0040.01816.82
7.1.00.0070.07022.31
7.0.200.0000.00716.53
7.0.140.0000.07721.93
7.0.60.0030.04019.90
7.0.50.0000.06317.91
7.0.40.0170.08020.13
7.0.30.0470.07320.13
7.0.20.0230.05020.26
7.0.10.0030.04320.23
7.0.00.0030.05720.23
5.6.280.0070.06721.12
5.6.210.0270.07320.63
5.6.200.0030.04318.19
5.6.190.0070.04020.55
5.6.180.0270.07720.60
5.6.170.0300.07720.52
5.6.160.0000.05720.43
5.6.150.0030.08018.18
5.6.140.0030.07018.13
5.6.130.0030.04318.28
5.6.120.0030.04320.82
5.6.110.0100.07021.04
5.6.100.0100.08321.14
5.6.90.0030.07020.99
5.6.80.0030.04020.41
5.5.350.0070.05720.32
5.5.340.0100.03317.92
5.5.330.0000.05020.57
5.5.320.0370.05320.20
5.5.310.0270.07720.27
5.5.300.0200.07017.98
5.5.290.0070.08018.04
5.5.280.0200.07020.82
5.5.270.0130.07720.79
5.5.260.0000.04320.79
5.5.250.0070.03720.61
5.5.240.0200.05720.18
5.4.450.0870.06019.59
5.4.440.0570.06319.47
5.4.430.0900.06019.70
5.4.420.0670.00019.51
5.4.410.0630.00019.21
5.4.400.0670.00018.91
5.4.390.0700.00019.08
5.4.380.0630.00019.21
5.4.370.0630.00018.98
5.4.360.0630.00019.02
5.4.350.0670.00019.02
5.4.340.0100.03112.04
5.4.320.0060.03612.53
5.4.310.0090.03412.52
5.4.300.0060.03612.53
5.4.290.0050.04512.52
5.4.280.0080.03712.42
5.4.270.0030.03812.42
5.4.260.0090.04112.42
5.4.250.0100.03812.41
5.4.240.0080.03812.42
5.4.230.0020.04012.41
5.4.220.0020.03912.41
5.4.210.0050.03512.41
5.4.200.0030.04012.41
5.4.190.0080.03412.41
5.4.180.0050.03712.41
5.4.170.0080.03412.42
5.4.160.0080.04112.42
5.4.150.0080.04012.41
5.4.140.0090.03712.09
5.4.130.0090.04412.08
5.4.120.0100.03412.04
5.4.110.0090.03312.04
5.4.100.0100.03212.04
5.4.90.0070.03612.03
5.4.80.0070.03712.03
5.4.70.0050.03612.03
5.4.60.0060.03512.03
5.4.50.0040.03712.04
5.4.40.0070.03412.02
5.4.30.0110.04312.01
5.4.20.0060.03612.02
5.4.10.0030.03812.02
5.4.00.0040.03811.51
5.3.290.0040.04012.80
5.3.280.0090.03512.71
5.3.270.0100.03412.72
5.3.260.0080.04612.71
5.3.250.0070.03812.72
5.3.240.0090.03512.72
5.3.230.0110.04012.71
5.3.220.0060.03712.68
5.3.210.0090.04112.68
5.3.200.0080.03312.68
5.3.190.0060.03812.68
5.3.180.0050.03812.68
5.3.170.0090.03412.66
5.3.160.0060.04612.67
5.3.150.0080.03512.68
5.3.140.0070.03512.66
5.3.130.0020.04312.65
5.3.120.0090.04112.65
5.3.110.0060.04012.66
5.3.100.0080.03512.11
5.3.90.0080.03412.08
5.3.80.0050.03712.08
5.3.70.0090.03412.07
5.3.60.0100.03612.07
5.3.50.0050.03912.00
5.3.40.0060.03612.00
5.3.30.0040.04211.95
5.3.20.0080.03311.73
5.3.10.0060.03311.70
5.3.00.0050.03611.68
5.2.170.0050.0379.18
5.2.160.0080.0259.18
5.2.150.0040.0319.18
5.2.140.0060.0319.18
5.2.130.0050.0319.14
5.2.120.0060.0319.14
5.2.110.0050.0309.15
5.2.100.0030.0319.14
5.2.90.0080.0399.14
5.2.80.0050.0349.14
5.2.70.0040.0319.13
5.2.60.0060.0309.10
5.2.50.0080.0279.07
5.2.40.0050.0319.04
5.2.30.0080.0279.02
5.2.20.0020.0309.01
5.2.10.0060.0278.93
5.2.00.0050.0298.78
5.1.60.0060.0228.07
5.1.50.0050.0268.06
5.1.40.0060.0248.05
5.1.30.0060.0278.40
5.1.20.0090.0228.42
5.1.10.0020.0288.15
5.1.00.0070.0248.14
5.0.50.0030.0206.62
5.0.40.0030.0196.48
5.0.30.0040.0326.30
5.0.20.0050.0176.26
5.0.10.0010.0296.24
5.0.00.0050.0306.24
4.4.90.0000.0174.77
4.4.80.0030.0154.76
4.4.70.0020.0164.75
4.4.60.0050.0124.75
4.4.50.0000.0184.77
4.4.40.0040.0324.71
4.4.30.0030.0214.76
4.4.20.0050.0154.84
4.4.10.0020.0184.85
4.4.00.0020.0254.76
4.3.110.0020.0184.67
4.3.100.0020.0164.66
4.3.90.0080.0154.64
4.3.80.0080.0204.58
4.3.70.0030.0264.63
4.3.60.0030.0144.63
4.3.50.0030.0154.62
4.3.40.0030.0294.53
4.3.30.0030.0143.29
4.3.20.0040.0203.26
4.3.10.0010.0213.22
4.3.00.0130.0237.23

preferences:
50.56 ms | 400 KiB | 5 Q