3v4l.org

run code in 300+ PHP versions simultaneously
<?php define('NUM_INSTANCES', 10); define('NUM_TESTS', 10000); class TestObject { public $a; public $b; public $c; public function __construct($a,$b,$c) { $this->a = $a; $this->b = $b; $this->c = $c; } } class Test { public function getObjects() { $a = array(); for ($i=0; $i<NUM_INSTANCES; $i++) $a[] = new TestObject('a','b','c'); return $a; } public function getArrays() { $a = array(); for ($i=0; $i<NUM_INSTANCES; $i++) $a[] = $this->buildArray('a', 'b', 'c'); return $a; } public function buildArray($a, $b, $c) { $array = array(); $array['a'] = $a; $array['b'] = $b; $array['c'] = $c; return $array; } public function useObject($o) { $a = $o->a; $b = $o->b; $o->c = 'xxx'; } public function useArray($o) { $a = $o['a']; $b = $o['b']; $o['c'] = 'xxx'; } } $test = new Test; // Benchmark with objects: $start = microtime(true); for ($i=0; $i<NUM_TESTS; $i++) { $x = $test->getObjects(); foreach ($x as $y) $test->useObject($y); } echo "\nObject time = " . (microtime(true)-$start) . "\n\n"; // Benchmark with arrays: $start = microtime(true); for ($i=0; $i<NUM_TESTS; $i++) { $x = $test->getArrays(); foreach ($x as $y) $test->useArray($y); } echo "\nArray time = " . (microtime(true)-$start) . "\n\n";
Output for 5.5.10
Object time = 0.091824054718018 Array time = 0.10977482795715
Output for 5.5.9
Object time = 0.12640595436096 Array time = 0.11454606056213
Output for 5.5.8
Object time = 0.095077991485596 Array time = 0.18988180160522
Output for 5.5.7
Object time = 0.09027886390686 Array time = 0.11443710327148
Output for 5.5.6
Object time = 0.11603689193726 Array time = 0.17254304885864
Output for 5.5.5
Object time = 0.083318948745728 Array time = 0.10960292816162
Output for 5.5.4
Object time = 0.13099098205566 Array time = 0.16764903068542
Output for 5.5.3
Object time = 0.13237905502319 Array time = 0.17250394821167
Output for 5.5.2
Object time = 0.12283992767334 Array time = 0.14790606498718
Output for 5.5.1
Object time = 0.13581895828247 Array time = 0.17795300483704
Output for 5.5.0
Object time = 0.092297077178955 Array time = 0.13854002952576
Output for 5.4.26
Object time = 0.13658213615417 Array time = 0.16862797737122
Output for 5.4.25
Object time = 0.09060001373291 Array time = 0.12423706054688
Output for 5.4.24
Object time = 0.11939597129822 Array time = 0.12064695358276
Output for 5.4.23
Object time = 0.13801312446594 Array time = 0.16110587120056
Output for 5.4.22
Object time = 0.08142614364624 Array time = 0.10480690002441
Output for 5.4.21
Object time = 0.082217931747437 Array time = 0.11171698570251
Output for 5.4.20
Object time = 0.080250024795532 Array time = 0.1096830368042
Output for 5.4.19
Object time = 0.087890863418579 Array time = 0.12701606750488
Output for 5.4.18
Object time = 0.084434986114502 Array time = 0.10840797424316
Output for 5.4.17
Object time = 0.092941999435425 Array time = 0.11197400093079
Output for 5.4.16
Object time = 0.085278987884521 Array time = 0.10472702980042
Output for 5.4.15
Object time = 0.092683792114258 Array time = 0.11813020706177
Output for 5.4.14
Object time = 0.092221975326538 Array time = 0.1363320350647
Output for 5.4.13
Object time = 0.083413124084473 Array time = 0.10248708724976
Output for 5.4.12
Object time = 0.13746309280396 Array time = 0.17409992218018
Output for 5.4.11
Object time = 0.083845138549805 Array time = 0.11132502555847
Output for 5.4.10
Object time = 0.092371940612793 Array time = 0.12956690788269
Output for 5.4.9
Object time = 0.099249124526978 Array time = 0.11526584625244
Output for 5.4.8
Object time = 0.14825892448425 Array time = 0.19637799263
Output for 5.4.7
Object time = 0.078212022781372 Array time = 0.10380005836487
Output for 5.4.6
Object time = 0.082151889801025 Array time = 0.10429120063782
Output for 5.4.5
Object time = 0.084625959396362 Array time = 0.11409592628479
Output for 5.4.4
Object time = 0.075511932373047 Array time = 0.11624002456665
Output for 5.4.3
Object time = 0.089516878128052 Array time = 0.11007905006409
Output for 5.4.2
Object time = 0.083979845046997 Array time = 0.10811495780945
Output for 5.4.1
Object time = 0.11769986152649 Array time = 0.1857271194458
Output for 5.4.0
Object time = 0.08214282989502 Array time = 0.12288284301758
Output for 5.3.28
Object time = 0.18470311164856 Array time = 0.13902807235718
Output for 5.3.27
Object time = 0.22457599639893 Array time = 0.21769189834595
Output for 5.3.26
Object time = 0.18837285041809 Array time = 0.15626907348633
Output for 5.3.25
Object time = 0.14768004417419 Array time = 0.17477893829346
Output for 5.3.24
Object time = 0.15625786781311 Array time = 0.14469909667969
Output for 5.3.23
Object time = 0.14509391784668 Array time = 0.13372302055359
Output for 5.3.22
Object time = 0.14294600486755 Array time = 0.21395397186279
Output for 5.3.21
Object time = 0.15561604499817 Array time = 0.15134596824646
Output for 5.3.20
Object time = 0.16409182548523 Array time = 0.15254092216492
Output for 5.3.19
Object time = 0.14912605285645 Array time = 0.13402700424194
Output for 5.3.18
Object time = 0.13781881332397 Array time = 0.14142799377441
Output for 5.3.17
Object time = 0.14337682723999 Array time = 0.15880703926086
Output for 5.3.16
Object time = 0.14538502693176 Array time = 0.1292839050293
Output for 5.3.15
Object time = 0.1612720489502 Array time = 0.14608812332153
Output for 5.3.14
Object time = 0.13334083557129 Array time = 0.13687086105347
Output for 5.3.13
Object time = 0.25397992134094 Array time = 0.23923206329346
Output for 5.3.12
Object time = 0.16416692733765 Array time = 0.14436888694763
Output for 5.3.11
Object time = 0.14297485351562 Array time = 0.13790512084961
Output for 5.3.10
Object time = 0.16395115852356 Array time = 0.13884902000427
Output for 5.3.9
Object time = 0.16826891899109 Array time = 0.1660737991333
Output for 5.3.8
Object time = 0.2009699344635 Array time = 0.14874601364136
Output for 5.3.7
Object time = 0.1495258808136 Array time = 0.13508081436157
Output for 5.3.6
Object time = 0.14524483680725 Array time = 0.14943814277649
Output for 5.3.5
Object time = 0.14226984977722 Array time = 0.16784286499023
Output for 5.3.4
Object time = 0.13717699050903 Array time = 0.1400101184845
Output for 5.3.3
Object time = 0.15021586418152 Array time = 0.1416449546814
Output for 5.3.2
Object time = 0.24597597122192 Array time = 0.17272591590881
Output for 5.3.1
Object time = 0.14967584609985 Array time = 0.15087485313416
Output for 5.3.0
Object time = 0.18485116958618 Array time = 0.14599394798279
Output for 5.2.17
Object time = 0.1978747844696 Array time = 0.16414999961853
Output for 5.2.16
Object time = 0.22153210639954 Array time = 0.23845791816711
Output for 5.2.15
Object time = 0.28055000305176 Array time = 0.28092408180237
Output for 5.2.14
Object time = 0.18651485443115 Array time = 0.21899700164795
Output for 5.2.13
Object time = 0.18627500534058 Array time = 0.2073290348053
Output for 5.2.12
Object time = 0.18165683746338 Array time = 0.21997809410095
Output for 5.2.11
Object time = 0.19504284858704 Array time = 0.16951704025269
Output for 5.2.10
Object time = 0.18961119651794 Array time = 0.23392105102539
Output for 5.2.9
Object time = 0.17905902862549 Array time = 0.17193007469177
Output for 5.2.8
Object time = 0.19843602180481 Array time = 0.18745994567871
Output for 5.2.7
Object time = 0.21692395210266 Array time = 0.17779517173767
Output for 5.2.6
Object time = 0.18438100814819 Array time = 0.16626691818237
Output for 5.2.5
Object time = 0.17806601524353 Array time = 0.1745970249176
Output for 5.2.4
Object time = 0.2113299369812 Array time = 0.19914412498474
Output for 5.2.3
Object time = 0.19853806495667 Array time = 0.18495893478394
Output for 5.2.2
Object time = 0.19865798950195 Array time = 0.19802808761597
Output for 5.2.1
Object time = 0.22989797592163 Array time = 0.19024896621704
Output for 5.2.0
Object time = 0.17885589599609 Array time = 0.18445801734924
Output for 5.1.6
Object time = 0.20323014259338 Array time = 0.19607019424438
Output for 5.1.5
Object time = 0.19964385032654 Array time = 0.18439602851868
Output for 5.1.4
Object time = 0.21686100959778 Array time = 0.16749501228333
Output for 5.1.3
Object time = 0.20384311676025 Array time = 0.16889905929565
Output for 5.1.2
Object time = 0.21946692466736 Array time = 0.17672801017761
Output for 5.1.1
Object time = 0.2742121219635 Array time = 0.30010890960693
Output for 5.1.0
Object time = 0.23335003852844 Array time = 0.2311098575592
Output for 5.0.5
Object time = 0.28535413742065 Array time = 0.28346085548401
Output for 5.0.4
Object time = 0.40039205551147 Array time = 0.34785103797913
Output for 5.0.3
Object time = 0.28663992881775 Array time = 0.26054501533508
Output for 5.0.2
Object time = 0.28468608856201 Array time = 0.30901408195496
Output for 5.0.1
Object time = 0.28299498558044 Array time = 0.26563596725464
Output for 5.0.0
Object time = 0.29888701438904 Array time = 0.26849412918091
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/ZogHd on line 8
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/ZogHd on line 8
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/ZogHd on line 8
Process exited with code 255.

preferences:
102.19 ms | 401 KiB | 125 Q