3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Bar { } class Foo { private $bar; public function __construct(Bar $bar) { $this->bar = $bar; } } $reflect = new ReflectionClass('foo'); $constructor = $reflect->getConstructor(); $bar = new Bar; $t1 = microtime(true); for ($i = 0; $i < 10000; $i++) { $foo = new Foo($bar); } $t2 = microtime(true); echo 'new keyword: ' . ($t2-$t1) . '<br />'; $t1 = microtime(true); for ($i = 0; $i < 10000; $i++) { $foo = $reflect->newInstanceArgs([$bar]); } $t2 = microtime(true); echo 'newinstanceargs: ' . ($t2-$t1) . '<br />'; $t1 = microtime(true); for ($i = 0; $i < 10000; $i++) { $foo = $reflect->newInstanceWithoutConstructor(); $constructor->invokeArgs($foo, [$bar]); } $t2 = microtime(true); echo 'newinstancewithoutconstructor: ' . ($t2-$t1) . '<br />'; $t1 = microtime(true); for ($i = 0; $i < 10000; $i++) { $foo = new Foo(...[$bar]); } $t2 = microtime(true); echo 'new keyword: ' . ($t2-$t1) . '<br />';
based on oXneA
Output for 7.1.0
new keyword: 0.0017549991607666<br />newinstanceargs: 0.0036311149597168<br />newinstancewithoutconstructor: 0.0041348934173584<br />new keyword: 0.0023550987243652<br />
Output for 7.0.14
new keyword: 0.0018510818481445<br />newinstanceargs: 0.0034441947937012<br />newinstancewithoutconstructor: 0.0044209957122803<br />new keyword: 0.0024399757385254<br />
Output for 7.0.6
new keyword: 0.001270055770874<br />newinstanceargs: 0.0026309490203857<br />newinstancewithoutconstructor: 0.0030369758605957<br />new keyword: 0.001784086227417<br />
Output for 7.0.5
new keyword: 0.0017240047454834<br />newinstanceargs: 0.0035450458526611<br />newinstancewithoutconstructor: 0.0040600299835205<br />new keyword: 0.0023541450500488<br />
Output for 7.0.4
new keyword: 0.0017678737640381<br />newinstanceargs: 0.003709077835083<br />newinstancewithoutconstructor: 0.0040898323059082<br />new keyword: 0.0023860931396484<br />
Output for 7.0.3
new keyword: 0.0014500617980957<br />newinstanceargs: 0.0029428005218506<br />newinstancewithoutconstructor: 0.0034999847412109<br />new keyword: 0.0019359588623047<br />
Output for 7.0.2
new keyword: 0.0010550022125244<br />newinstanceargs: 0.0022170543670654<br />newinstancewithoutconstructor: 0.002593994140625<br />new keyword: 0.0015277862548828<br />
Output for 7.0.1
new keyword: 0.0016238689422607<br />newinstanceargs: 0.0032901763916016<br />newinstancewithoutconstructor: 0.0037009716033936<br />new keyword: 0.0021510124206543<br />
Output for 7.0.0
new keyword: 0.0012869834899902<br />newinstanceargs: 0.0027248859405518<br />newinstancewithoutconstructor: 0.003169059753418<br />new keyword: 0.0017740726470947<br />
Output for 5.6.28
new keyword: 0.0042588710784912<br />newinstanceargs: 0.0079360008239746<br />newinstancewithoutconstructor: 0.0093569755554199<br />new keyword: 0.005605936050415<br />
Output for 5.6.21
new keyword: 0.0038268566131592<br />newinstanceargs: 0.0076520442962646<br />newinstancewithoutconstructor: 0.0084009170532227<br />new keyword: 0.0053300857543945<br />
Output for 5.6.20
new keyword: 0.0030088424682617<br />newinstanceargs: 0.0060129165649414<br />newinstancewithoutconstructor: 0.006309986114502<br />new keyword: 0.0039269924163818<br />
Output for 5.6.19
new keyword: 0.0038537979125977<br />newinstanceargs: 0.0069329738616943<br />newinstancewithoutconstructor: 0.0079131126403809<br />new keyword: 0.0048768520355225<br />
Output for 5.6.18
new keyword: 0.0025699138641357<br />newinstanceargs: 0.0046110153198242<br />newinstancewithoutconstructor: 0.0053529739379883<br />new keyword: 0.0036699771881104<br />
Output for 5.6.17
new keyword: 0.0036611557006836<br />newinstanceargs: 0.0072119235992432<br />newinstancewithoutconstructor: 0.0080568790435791<br />new keyword: 0.0051510334014893<br />
Output for 5.6.16
new keyword: 0.0027329921722412<br />newinstanceargs: 0.0054090023040771<br />newinstancewithoutconstructor: 0.0061500072479248<br />new keyword: 0.004058837890625<br />
Output for 5.6.15
new keyword: 0.0038189888000488<br />newinstanceargs: 0.0077531337738037<br />newinstancewithoutconstructor: 0.008249044418335<br />new keyword: 0.0053210258483887<br />
Output for 5.6.14
new keyword: 0.0038819313049316<br />newinstanceargs: 0.0075740814208984<br />newinstancewithoutconstructor: 0.0082869529724121<br />new keyword: 0.0053169727325439<br />
Output for 5.6.13
new keyword: 0.0041549205780029<br />newinstanceargs: 0.0078151226043701<br />newinstancewithoutconstructor: 0.0080220699310303<br />new keyword: 0.0047011375427246<br />
Output for 5.6.12
new keyword: 0.0039799213409424<br />newinstanceargs: 0.0075960159301758<br />newinstancewithoutconstructor: 0.0085170269012451<br />new keyword: 0.0054969787597656<br />
Output for 5.6.11
new keyword: 0.0038928985595703<br />newinstanceargs: 0.0073709487915039<br />newinstancewithoutconstructor: 0.0081219673156738<br />new keyword: 0.0053138732910156<br />
Output for 5.6.10
new keyword: 0.0025410652160645<br />newinstanceargs: 0.0050699710845947<br />newinstancewithoutconstructor: 0.0059659481048584<br />new keyword: 0.0038621425628662<br />
Output for 5.6.9
new keyword: 0.0035989284515381<br />newinstanceargs: 0.0062229633331299<br />newinstancewithoutconstructor: 0.0071661472320557<br />new keyword: 0.0047318935394287<br />
Output for 5.6.8
new keyword: 0.0040159225463867<br />newinstanceargs: 0.0086009502410889<br />newinstancewithoutconstructor: 0.0092310905456543<br />new keyword: 0.0061080455780029<br />
Output for 5.6.7
new keyword: 0.002701997756958<br />newinstanceargs: 0.0052070617675781<br />newinstancewithoutconstructor: 0.0060431957244873<br />new keyword: 0.0039150714874268<br />
Output for 5.5.24 - 5.5.35
Parse error: syntax error, unexpected '.' in /in/NepLY on line 53
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '.', expecting ')' in /in/NepLY on line 53
Process exited with code 255.
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[', expecting ')' in /in/NepLY on line 33
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[', expecting ')' in /in/NepLY on line 33
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/NepLY on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/NepLY on line 7
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/NepLY on line 7
Process exited with code 255.