3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php define('NUMBER_OF_THINGS', 100000); class Something{ const SOME_MAX_VALUE = 100; protected $field; public function setField($value){ $this->field = $value; return $this; } public function getField(){ return $this->field; } } $aBunchOfThings = array(); for($i=0; $i<NUMBER_OF_THINGS; $i++){ $aThing = new Something(); $aBunchOfThings[] = $aThing->setField(rand(1, Something::SOME_MAX_VALUE)); } function searchForeach($array, $needle){ $results = array(); foreach($array as $key => $thing){ if($thing->getField() == $needle){ $result[] = $needle; } } return $result; } function searchArrayFilter($array, $needle){ return array_filter($array, function($thing) use ($needle){ return $thing->getField() == $needle; }); } $needle = 50; $start = microtime(true); $result = searchForeach($aBunchOfThings, $needle); $durationForeach = microtime(true) - $start; $start = microtime(true); $result = searchArrayFilter($aBunchOfThings, $needle); $durationArrayFilter = microtime(true) - $start; echo "Function | Time\n"; echo "-----------------------------------------\n"; echo "searchForeach | $durationForeach\n"; echo "searchArrayFilter | $durationArrayFilter\n"; ?>
based on Fgi5h
Output for 7.1.0
Function | Time ----------------------------------------- searchForeach | 0.010304927825928 searchArrayFilter | 0.018338203430176
Output for 7.0.14
Function | Time ----------------------------------------- searchForeach | 0.010358810424805 searchArrayFilter | 0.019659996032715
Output for 7.0.6
Function | Time ----------------------------------------- searchForeach | 0.008620023727417 searchArrayFilter | 0.021585941314697
Output for 7.0.5
Function | Time ----------------------------------------- searchForeach | 0.0095100402832031 searchArrayFilter | 0.019818067550659
Output for 7.0.4
Function | Time ----------------------------------------- searchForeach | 0.0085749626159668 searchArrayFilter | 0.017625093460083
Output for 7.0.3
Function | Time ----------------------------------------- searchForeach | 0.0082859992980957 searchArrayFilter | 0.018044948577881
Output for 7.0.2
Function | Time ----------------------------------------- searchForeach | 0.0075428485870361 searchArrayFilter | 0.01565408706665
Output for 7.0.1
Function | Time ----------------------------------------- searchForeach | 0.0073308944702148 searchArrayFilter | 0.015799999237061
Output for 7.0.0
Function | Time ----------------------------------------- searchForeach | 0.008620023727417 searchArrayFilter | 0.018442869186401
Output for hhvm-3.12.0
Function | Time ----------------------------------------- searchForeach | 0.014279842376709 searchArrayFilter | 0.025076866149902
Output for hhvm-3.10.0
Function | Time ----------------------------------------- searchForeach | 0.018196105957031 searchArrayFilter | 0.027340888977051
Output for 5.6.28
Function | Time ----------------------------------------- searchForeach | 0.037487030029297 searchArrayFilter | 0.037965059280396
Output for 5.6.21
Function | Time ----------------------------------------- searchForeach | 0.035729169845581 searchArrayFilter | 0.035482883453369
Output for 5.6.20
Function | Time ----------------------------------------- searchForeach | 0.031527996063232 searchArrayFilter | 0.034275054931641
Output for 5.6.19
Function | Time ----------------------------------------- searchForeach | 0.030696153640747 searchArrayFilter | 0.033492088317871
Output for 5.6.18
Function | Time ----------------------------------------- searchForeach | 0.033956050872803 searchArrayFilter | 0.034582138061523
Output for 5.6.17
Function | Time ----------------------------------------- searchForeach | 0.030433893203735 searchArrayFilter | 0.033914804458618
Output for 5.6.16
Function | Time ----------------------------------------- searchForeach | 0.050369024276733 searchArrayFilter | 0.04557204246521
Output for 5.6.15
Function | Time ----------------------------------------- searchForeach | 0.031588077545166 searchArrayFilter | 0.032840967178345
Output for 5.6.14
Function | Time ----------------------------------------- searchForeach | 0.030167102813721 searchArrayFilter | 0.033030033111572
Output for 5.6.13
Function | Time ----------------------------------------- searchForeach | 0.033351898193359 searchArrayFilter | 0.034940004348755
Output for 5.6.12
Function | Time ----------------------------------------- searchForeach | 0.030748128890991 searchArrayFilter | 0.033730030059814
Output for 5.6.11
Function | Time ----------------------------------------- searchForeach | 0.035503149032593 searchArrayFilter | 0.035305023193359
Output for 5.6.10
Function | Time ----------------------------------------- searchForeach | 0.035849094390869 searchArrayFilter | 0.035161018371582
Output for 5.6.9
Function | Time ----------------------------------------- searchForeach | 0.03527307510376 searchArrayFilter | 0.03567099571228
Output for 5.6.8
Function | Time ----------------------------------------- searchForeach | 0.034713983535767 searchArrayFilter | 0.034868955612183
Output for 5.5.35
Function | Time ----------------------------------------- searchForeach | 0.035002946853638 searchArrayFilter | 0.036468982696533
Output for 5.5.34
Function | Time ----------------------------------------- searchForeach | 0.03532600402832 searchArrayFilter | 0.03541111946106
Output for 5.5.33
Function | Time ----------------------------------------- searchForeach | 0.03410005569458 searchArrayFilter | 0.035398006439209
Output for 5.5.32
Function | Time ----------------------------------------- searchForeach | 0.031924962997437 searchArrayFilter | 0.033565044403076
Output for 5.5.31
Function | Time ----------------------------------------- searchForeach | 0.031858921051025 searchArrayFilter | 0.033143997192383
Output for 5.5.30
Function | Time ----------------------------------------- searchForeach | 0.045762062072754 searchArrayFilter | 0.047961950302124
Output for 5.5.29
Function | Time ----------------------------------------- searchForeach | 0.033746957778931 searchArrayFilter | 0.034861087799072
Output for 5.5.28
Function | Time ----------------------------------------- searchForeach | 0.03562593460083 searchArrayFilter | 0.035712003707886
Output for 5.5.27
Function | Time ----------------------------------------- searchForeach | 0.038321971893311 searchArrayFilter | 0.035309076309204
Output for 5.5.26
Function | Time ----------------------------------------- searchForeach | 0.034302949905396 searchArrayFilter | 0.035316944122314
Output for 5.5.25
Function | Time ----------------------------------------- searchForeach | 0.036035060882568 searchArrayFilter | 0.036275148391724
Output for 5.5.24
Function | Time ----------------------------------------- searchForeach | 0.035949945449829 searchArrayFilter | 0.034340143203735
Output for 5.4.45
Function | Time ----------------------------------------- searchForeach | 0.053569078445435 searchArrayFilter | 0.045904874801636
Output for 5.4.44
Function | Time ----------------------------------------- searchForeach | 0.051938056945801 searchArrayFilter | 0.047633171081543
Output for 5.4.43
Function | Time ----------------------------------------- searchForeach | 0.06554913520813 searchArrayFilter | 0.05100417137146
Output for 5.4.42
Function | Time ----------------------------------------- searchForeach | 0.061908960342407 searchArrayFilter | 0.046564817428589
Output for 5.4.41
Function | Time ----------------------------------------- searchForeach | 0.052325963973999 searchArrayFilter | 0.047122001647949
Output for 5.4.40
Function | Time ----------------------------------------- searchForeach | 0.054980039596558 searchArrayFilter | 0.056012868881226
Output for 5.4.39
Function | Time ----------------------------------------- searchForeach | 0.05811595916748 searchArrayFilter | 0.064559936523438
Output for 5.4.38
Function | Time ----------------------------------------- searchForeach | 0.059598922729492 searchArrayFilter | 0.056336879730225
Output for 5.4.37
Function | Time ----------------------------------------- searchForeach | 0.070731163024902 searchArrayFilter | 0.041774988174438
Output for 5.4.36
Function | Time ----------------------------------------- searchForeach | 0.038640022277832 searchArrayFilter | 0.043018102645874
Output for 5.4.35
Function | Time ----------------------------------------- searchForeach | 0.055258989334106 searchArrayFilter | 0.0624680519104
Output for 5.4.34
Function | Time ----------------------------------------- searchForeach | 0.072150945663452 searchArrayFilter | 0.044857978820801
Output for 5.4.32
Function | Time ----------------------------------------- searchForeach | 0.039155006408691 searchArrayFilter | 0.053889989852905
Output for 5.4.31
Function | Time ----------------------------------------- searchForeach | 0.034588098526001 searchArrayFilter | 0.038338899612427
Output for 5.4.30
Function | Time ----------------------------------------- searchForeach | 0.035797119140625 searchArrayFilter | 0.039626836776733
Output for 5.4.29
Function | Time ----------------------------------------- searchForeach | 0.034560918807983 searchArrayFilter | 0.036819934844971
Output for 5.4.28
Function | Time ----------------------------------------- searchForeach | 0.035150051116943 searchArrayFilter | 0.036118984222412
Output for 5.4.27
Function | Time ----------------------------------------- searchForeach | 0.035696983337402 searchArrayFilter | 0.036839962005615
Output for 5.4.26
Function | Time ----------------------------------------- searchForeach | 0.035110950469971 searchArrayFilter | 0.03699517250061
Output for 5.4.25
Function | Time ----------------------------------------- searchForeach | 0.035326957702637 searchArrayFilter | 0.040709972381592
Output for 5.4.24
Function | Time ----------------------------------------- searchForeach | 0.034420967102051 searchArrayFilter | 0.036679983139038
Output for 5.4.23
Function | Time ----------------------------------------- searchForeach | 0.034952878952026 searchArrayFilter | 0.036651134490967
Output for 5.4.22
Function | Time ----------------------------------------- searchForeach | 0.034663915634155 searchArrayFilter | 0.037286996841431
Output for 5.4.21
Function | Time ----------------------------------------- searchForeach | 0.034940958023071 searchArrayFilter | 0.03926420211792
Output for 5.4.20
Function | Time ----------------------------------------- searchForeach | 0.038522958755493 searchArrayFilter | 0.036216974258423
Output for 5.4.19
Function | Time ----------------------------------------- searchForeach | 0.034147977828979 searchArrayFilter | 0.038241147994995
Output for 5.4.18
Function | Time ----------------------------------------- searchForeach | 0.034589052200317 searchArrayFilter | 0.038707971572876
Output for 5.4.17
Function | Time ----------------------------------------- searchForeach | 0.035603046417236 searchArrayFilter | 0.036149024963379
Output for 5.4.16
Function | Time ----------------------------------------- searchForeach | 0.034197092056274 searchArrayFilter | 0.037609100341797
Output for 5.4.15
Function | Time ----------------------------------------- searchForeach | 0.03741192817688 searchArrayFilter | 0.036565065383911
Output for 5.4.14
Function | Time ----------------------------------------- searchForeach | 0.035444021224976 searchArrayFilter | 0.036770820617676
Output for 5.4.13
Function | Time ----------------------------------------- searchForeach | 0.035892963409424 searchArrayFilter | 0.036901950836182
Output for 5.4.12
Function | Time ----------------------------------------- searchForeach | 0.035565137863159 searchArrayFilter | 0.03727388381958
Output for 5.4.11
Function | Time ----------------------------------------- searchForeach | 0.038274049758911 searchArrayFilter | 0.041175842285156
Output for 5.4.10
Function | Time ----------------------------------------- searchForeach | 0.034842967987061 searchArrayFilter | 0.038688182830811
Output for 5.4.9
Function | Time ----------------------------------------- searchForeach | 0.056246995925903 searchArrayFilter | 0.038252115249634
Output for 5.4.8
Function | Time ----------------------------------------- searchForeach | 0.037449836730957 searchArrayFilter | 0.039844036102295
Output for 5.4.7
Function | Time ----------------------------------------- searchForeach | 0.0399489402771 searchArrayFilter | 0.041278123855591
Output for 5.4.6
Function | Time ----------------------------------------- searchForeach | 0.04562520980835 searchArrayFilter | 0.046490907669067
Output for 5.4.5
Function | Time ----------------------------------------- searchForeach | 0.035736083984375 searchArrayFilter | 0.040339946746826
Output for 5.4.4
Function | Time ----------------------------------------- searchForeach | 0.040127038955688 searchArrayFilter | 0.039857864379883
Output for 5.4.3
Function | Time ----------------------------------------- searchForeach | 0.035958051681519 searchArrayFilter | 0.041141986846924
Output for 5.4.2
Function | Time ----------------------------------------- searchForeach | 0.038103103637695 searchArrayFilter | 0.042726039886475
Output for 5.4.1
Function | Time ----------------------------------------- searchForeach | 0.036339998245239 searchArrayFilter | 0.039180994033813
Output for 5.4.0
Function | Time ----------------------------------------- searchForeach | 0.036234140396118 searchArrayFilter | 0.037081003189087
Output for 5.3.0 - 5.3.29
Fatal error: Allowed memory size of 67108864 bytes exhausted (tried to allocate 71 bytes) in /in/8v719 on line 25
Process exited with code 255.
Output for 5.1.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/8v719 on line 34
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/8v719 on line 34
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/8v719 on line 5
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_CONST, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/8v719 on line 5
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/8v719 on line 5
Process exited with code 255.