3v4l.org

run code in 300+ PHP versions simultaneously
<?php interface DataTransferObject { public static function fromParams(array $params); public function asArray(); } trait DataTransferTrait { private static $mutable; private function __construct(array $params) { foreach ($params as $key => $value) { $this->{'set' . str_replace(' ', '', ucwords(str_replace('_', ' ', $key)))}($value); } unset($mutable); } public static function fromParams(array $params) { return new static($params); } public function asArray() { return get_object_vars($this); } public function __call($method, $args) { if (isset($self::mutable) && substr($method, 0, 3) == 'set' && property_exists($this, lcfirst(substr($method, 3)))) { $this->{lcfirst(substr($method, 3))} = reset($args); } } } abstract class Command { } final class MyCommand extends Command implements DataTransferObject { use DataTransferTrait; private $foo; private $bar; private function setBar($value) { $this->bar = $value; } } $foo = MyCommand::fromParams(array('foo' => 'foo', 'bar' => 'bar', 'meh' => 'meh')); $foo->setFoo('newfoo'); $foo->setDog('dog'); var_dump($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)
5.4.340.0060.03512.04
5.4.320.0040.03812.53
5.4.310.0020.04412.52
5.4.300.0050.04112.52
5.4.290.0070.05412.52
5.4.280.0040.04112.41
5.4.270.0080.04212.42
5.4.260.0080.04912.42
5.4.250.0070.04312.42
5.4.240.0070.03512.41
5.4.230.0060.03812.41
5.4.220.0070.03612.41
5.4.210.0080.03412.41
5.4.200.0080.03512.41
5.4.190.0070.04112.41
5.4.180.0100.04912.41
5.4.170.0080.03512.41
5.4.160.0120.03212.41
5.4.150.0030.03812.41
5.4.140.0060.03612.09
5.4.130.0100.03112.08
5.4.120.0060.03512.04
5.4.110.0060.03512.04
5.4.100.0070.03612.04
5.4.90.0060.04012.04
5.4.80.0060.04112.04
5.4.70.0110.04812.04
5.4.60.0060.05112.03
5.4.50.0070.05412.04
5.4.40.0100.04712.02
5.4.30.0070.04212.02
5.4.20.0050.04412.02
5.4.10.0060.04612.02
5.4.00.0080.04211.51
5.3.290.0120.04612.80
5.3.280.0130.05312.71
5.3.270.0050.04112.72
5.3.260.0110.04212.72
5.3.250.0080.03812.72
5.3.240.0070.04612.72
5.3.230.0090.04112.71
5.3.220.0070.03912.68
5.3.210.0060.04012.68
5.3.200.0060.03912.68
5.3.190.0080.03612.68
5.3.180.0050.04712.67
5.3.170.0070.03912.67
5.3.160.0110.03212.68
5.3.150.0060.03712.67
5.3.140.0060.03812.66
5.3.130.0060.03912.66
5.3.120.0050.04212.66
5.3.110.0090.03912.66
5.3.100.0060.03612.13
5.3.90.0050.04112.11
5.3.80.0080.03412.10
5.3.70.0060.03712.10
5.3.60.0060.03612.08
5.3.50.0080.03612.03
5.3.40.0100.04312.03
5.3.30.0050.03811.98
5.3.20.0040.03911.77
5.3.10.0040.03811.73
5.3.00.0090.03211.72
5.2.170.0070.0289.22
5.2.160.0030.0319.23
5.2.150.0050.0309.22
5.2.140.0090.0319.22
5.2.130.0060.0289.18
5.2.120.0040.0309.18
5.2.110.0080.0269.19
5.2.100.0040.0289.18
5.2.90.0040.0299.18
5.2.80.0030.0359.18
5.2.70.0050.0309.18
5.2.60.0040.0319.14
5.2.50.0060.0339.11
5.2.40.0070.0349.09
5.2.30.0060.0389.05
5.2.20.0030.0389.04
5.2.10.0050.0278.95
5.2.00.0050.0338.81
5.1.60.0030.0258.10
5.1.50.0050.0278.09
5.1.40.0050.0318.07
5.1.30.0050.0298.42
5.1.20.0170.0598.45
5.1.10.0050.0268.17
5.1.00.0060.0268.17
5.0.50.0050.0296.64
5.0.40.0090.0156.50
5.0.30.0050.0406.31
5.0.20.0030.0226.28
5.0.10.0060.0436.26
5.0.00.0180.0726.25
4.4.90.0030.0194.77
4.4.80.0030.0174.76
4.4.70.0040.0144.75
4.4.60.0000.0214.75
4.4.50.0020.0164.77
4.4.40.0040.0284.71
4.4.30.0010.0174.76
4.4.20.0030.0204.84
4.4.10.0000.0184.85
4.4.00.0030.0244.76
4.3.110.0020.0164.67
4.3.100.0020.0164.66
4.3.90.0030.0144.64
4.3.80.0020.0284.58
4.3.70.0070.0104.63
4.3.60.0030.0154.63
4.3.50.0050.0144.63
4.3.40.0020.0254.54
4.3.30.0000.0183.29
4.3.20.0010.0173.26
4.3.10.0030.0143.22
4.3.00.0030.0237.20

preferences:
141.56 ms | 1386 KiB | 7 Q