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; $aBar = [$bar]; $t1 = microtime(true); for ($i = 0; $i < 10000; $i++) { $foo = new Foo($bar); } $t2 = microtime(true); echo 'new keyword: ' . ($t2-$t1) . "\n\n"; $t1 = microtime(true); for ($i = 0; $i < 10000; $i++) { $foo = $reflect->newInstanceArgs($aBar); } $t2 = microtime(true); echo 'newinstanceargs: ' . ($t2-$t1) . "\n\n"; $t1 = microtime(true); for ($i = 0; $i < 10000; $i++) { $foo = $reflect->newInstanceWithoutConstructor(); $constructor->invokeArgs($foo, $aBar); } $t2 = microtime(true); echo 'newinstancewithoutconstructor: ' . ($t2-$t1) . "\n\n"; $t1 = microtime(true); for ($i = 0; $i < 10000; $i++) { $foo = new Foo(...$aBar); } $t2 = microtime(true); echo 'new keyword 2: ' . ($t2-$t1) . "\n\n";
based on NepLY
Output for 7.1.0
new keyword: 0.0017471313476562 newinstanceargs: 0.0029759407043457 newinstancewithoutconstructor: 0.0035660266876221 new keyword 2: 0.0018100738525391
Output for 7.0.14
new keyword: 0.0017790794372559 newinstanceargs: 0.0030980110168457 newinstancewithoutconstructor: 0.0039730072021484 new keyword 2: 0.0018448829650879
Output for 7.0.6
new keyword: 0.0016670227050781 newinstanceargs: 0.0029330253601074 newinstancewithoutconstructor: 0.0033180713653564 new keyword 2: 0.0017058849334717
Output for 7.0.5
new keyword: 0.0010490417480469 newinstanceargs: 0.0018270015716553 newinstancewithoutconstructor: 0.0021929740905762 new keyword 2: 0.0011649131774902
Output for 7.0.4
new keyword: 0.0017030239105225 newinstanceargs: 0.0028879642486572 newinstancewithoutconstructor: 0.0033659934997559 new keyword 2: 0.0016980171203613
Output for 7.0.3
new keyword: 0.0011141300201416 newinstanceargs: 0.0018928050994873 newinstancewithoutconstructor: 0.0022590160369873 new keyword 2: 0.0011980533599854
Output for 7.0.2
new keyword: 0.0012359619140625 newinstanceargs: 0.0022158622741699 newinstancewithoutconstructor: 0.0026178359985352 new keyword 2: 0.0013370513916016
Output for 7.0.1
new keyword: 0.0012369155883789 newinstanceargs: 0.0021538734436035 newinstancewithoutconstructor: 0.002485990524292 new keyword 2: 0.0012760162353516
Output for 7.0.0
new keyword: 0.0010418891906738 newinstanceargs: 0.0025119781494141 newinstancewithoutconstructor: 0.0025248527526855 new keyword 2: 0.0011439323425293
Output for hhvm-3.12.0
new keyword: 0.0019960403442383 newinstanceargs: 0.0067839622497559 newinstancewithoutconstructor: 0.010976076126099 new keyword 2: 0.0023360252380371
Output for hhvm-3.10.0
new keyword: 0.0024471282958984 newinstanceargs: 0.008173942565918 newinstancewithoutconstructor: 0.012665987014771 new keyword 2: 0.0027291774749756
Output for 5.6.28
new keyword: 0.004295825958252 newinstanceargs: 0.0064430236816406 newinstancewithoutconstructor: 0.0080921649932861 new keyword 2: 0.0044660568237305
Output for 5.6.21
new keyword: 0.0034220218658447 newinstanceargs: 0.0057089328765869 newinstancewithoutconstructor: 0.0067110061645508 new keyword 2: 0.0040631294250488
Output for 5.6.20
new keyword: 0.0038630962371826 newinstanceargs: 0.0065600872039795 newinstancewithoutconstructor: 0.006432056427002 new keyword 2: 0.0035951137542725
Output for 5.6.19
new keyword: 0.003788948059082 newinstanceargs: 0.0058169364929199 newinstancewithoutconstructor: 0.0069279670715332 new keyword 2: 0.0038940906524658
Output for 5.6.18
new keyword: 0.002485990524292 newinstanceargs: 0.0037319660186768 newinstancewithoutconstructor: 0.0045039653778076 new keyword 2: 0.0026569366455078
Output for 5.6.17
new keyword: 0.0043900012969971 newinstanceargs: 0.0071508884429932 newinstancewithoutconstructor: 0.0079100131988525 new keyword 2: 0.0044209957122803
Output for 5.6.16
new keyword: 0.0041019916534424 newinstanceargs: 0.0067839622497559 newinstancewithoutconstructor: 0.0077469348907471 new keyword 2: 0.0047969818115234
Output for 5.6.15
new keyword: 0.0040831565856934 newinstanceargs: 0.0069270133972168 newinstancewithoutconstructor: 0.0078141689300537 new keyword 2: 0.004680871963501
Output for 5.6.14
new keyword: 0.0028271675109863 newinstanceargs: 0.0047929286956787 newinstancewithoutconstructor: 0.0054831504821777 new keyword 2: 0.003425121307373
Output for 5.6.13
new keyword: 0.0040898323059082 newinstanceargs: 0.0067229270935059 newinstancewithoutconstructor: 0.0076978206634521 new keyword 2: 0.0043010711669922
Output for 5.6.12
new keyword: 0.0038659572601318 newinstanceargs: 0.0067458152770996 newinstancewithoutconstructor: 0.0073869228363037 new keyword 2: 0.0045931339263916
Output for 5.6.11
new keyword: 0.0038599967956543 newinstanceargs: 0.0064690113067627 newinstancewithoutconstructor: 0.0073518753051758 new keyword 2: 0.0045042037963867
Output for 5.6.10
new keyword: 0.0040137767791748 newinstanceargs: 0.0067830085754395 newinstancewithoutconstructor: 0.0077288150787354 new keyword 2: 0.0047698020935059
Output for 5.6.9
new keyword: 0.0028541088104248 newinstanceargs: 0.0054872035980225 newinstancewithoutconstructor: 0.0056710243225098 new keyword 2: 0.003957986831665
Output for 5.6.8
new keyword: 0.0038027763366699 newinstanceargs: 0.006566047668457 newinstancewithoutconstructor: 0.0074899196624756 new keyword 2: 0.0045680999755859
Output for 5.5.24 - 5.5.35
Parse error: syntax error, unexpected '.' in /in/rvpK0 on line 54
Process exited with code 255.
Output for 5.4.0 - 5.4.45
Parse error: syntax error, unexpected '.', expecting ')' in /in/rvpK0 on line 54
Process exited with code 255.
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/rvpK0 on line 19
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/rvpK0 on line 19
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/rvpK0 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/rvpK0 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/rvpK0 on line 7
Process exited with code 255.