3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php echo '<pre>'; // Setup input array $input = []; for ($i = 0; $i < 100000; $i++) { $input[] = rand(~PHP_INT_MAX, PHP_INT_MAX); } $foreach_if_times = []; $array_filter_times = []; for ($i = 0; $i < 100; $i++) { $start = microtime(true); array_filter($input, function ($item) { return ($item > 0); }); $array_filter_times[] = microtime(true) - $start; } for ($i = 0; $i < 100; $i++) { $start = microtime(true); $result = []; foreach ($input as $item) { if ($item > 0) { $result[] = $item; } } $foreach_if_times[] = microtime(true) - $start; } echo sprintf("Avg time: %.8f\n", $array_filter_avg = array_sum($array_filter_times) / count($array_filter_times)); echo sprintf("Avg time: %.8f\n", $foreach_if_avg = array_sum($foreach_if_times) / count($foreach_if_times)); echo sprintf("Difference: %.8f\nRatio: %.8f\n", $array_filter_avg - $foreach_if_avg, $array_filter_avg / $foreach_if_avg);
based on Sci9E
Output for 7.1.0
<pre>Avg time: 0.00385720 Avg time: -0.00206323 Difference: 0.00592043 Ratio: -1.86950126
Output for 7.0.14
<pre>Avg time: 0.00276728 Avg time: -0.00120141 Difference: 0.00396868 Ratio: -2.30336809
Output for 7.0.6
<pre>Avg time: 0.00556777 Avg time: 0.00093281 Difference: 0.00463496 Ratio: 5.96882284
Output for 7.0.5
<pre>Avg time: 0.00512498 Avg time: 0.00090991 Difference: 0.00421507 Ratio: 5.63241825
Output for 7.0.4
<pre>Avg time: 0.00554848 Avg time: 0.00094742 Difference: 0.00460106 Ratio: 5.85641091
Output for 7.0.3
<pre>Avg time: 0.00560783 Avg time: 0.00093081 Difference: 0.00467702 Ratio: 6.02468174
Output for 7.0.2
<pre>Avg time: 0.00532743 Avg time: 0.00115910 Difference: 0.00416833 Ratio: 4.59619261
Output for 7.0.1
<pre>Avg time: 0.00529931 Avg time: 0.00093255 Difference: 0.00436676 Ratio: 5.68261155
Output for 7.0.0
<pre>Avg time: 0.00556740 Avg time: 0.00092808 Difference: 0.00463932 Ratio: 5.99881829
Output for hhvm-3.12.0
<pre>Avg time: 0.01144165 Avg time: 0.00375373 Difference: 0.00768792 Ratio: 3.04807781
Output for hhvm-3.10.0
<pre>Avg time: 0.01438093 Avg time: 0.00474394 Difference: 0.00963700 Ratio: 3.03143459
Output for 5.6.28
<pre>Avg time: 0.01137298 Avg time: -0.00159233 Difference: 0.01296531 Ratio: -7.14237052
Output for 5.6.21
<pre>Avg time: 0.01126138 Avg time: 0.00291156 Difference: 0.00834982 Ratio: 3.86781658
Output for 5.6.20
<pre>Avg time: 0.01163625 Avg time: 0.00296241 Difference: 0.00867383 Ratio: 3.92796207
Output for 5.6.19
<pre>Avg time: 0.01171063 Avg time: 0.00302119 Difference: 0.00868944 Ratio: 3.87616282
Output for 5.6.18
<pre>Avg time: 0.01164371 Avg time: 0.00302363 Difference: 0.00862008 Ratio: 3.85090017
Output for 5.6.17
<pre>Avg time: 0.01157593 Avg time: 0.00296065 Difference: 0.00861528 Ratio: 3.90992424
Output for 5.6.16
<pre>Avg time: 0.01184182 Avg time: 0.00291999 Difference: 0.00892184 Ratio: 4.05543748
Output for 5.6.15
<pre>Avg time: 0.01111944 Avg time: 0.00286311 Difference: 0.00825633 Ratio: 3.88369314
Output for 5.6.14
<pre>Avg time: 0.01171549 Avg time: 0.00297885 Difference: 0.00873664 Ratio: 3.93289046
Output for 5.6.13
<pre>Avg time: 0.01174437 Avg time: 0.00296547 Difference: 0.00877890 Ratio: 3.96037491
Output for 5.6.12
<pre>Avg time: 0.01144799 Avg time: 0.00310976 Difference: 0.00833822 Ratio: 3.68130792
Output for 5.6.11
<pre>Avg time: 0.01199138 Avg time: 0.00291727 Difference: 0.00907411 Ratio: 4.11047800
Output for 5.6.10
<pre>Avg time: 0.01130872 Avg time: 0.00292556 Difference: 0.00838316 Ratio: 3.86549308
Output for 5.6.9
<pre>Avg time: 0.01363769 Avg time: 0.00297292 Difference: 0.01066476 Ratio: 4.58729973
Output for 5.6.8
<pre>Avg time: 0.01246495 Avg time: 0.00297904 Difference: 0.00948591 Ratio: 4.18422104
Output for 5.5.35
<pre>Avg time: 0.00970715 Avg time: 0.00257369 Difference: 0.00713347 Ratio: 3.77169328
Output for 5.5.34
<pre>Avg time: 0.01057472 Avg time: 0.00301708 Difference: 0.00755764 Ratio: 3.50494801
Output for 5.5.33
<pre>Avg time: 0.01072218 Avg time: 0.00301091 Difference: 0.00771126 Ratio: 3.56110333
Output for 5.5.32
<pre>Avg time: 0.01019912 Avg time: 0.00305351 Difference: 0.00714561 Ratio: 3.34012604
Output for 5.5.31
<pre>Avg time: 0.01025692 Avg time: 0.00301208 Difference: 0.00724483 Ratio: 3.40525583
Output for 5.5.30
<pre>Avg time: 0.01063446 Avg time: 0.00302338 Difference: 0.00761108 Ratio: 3.51741114
Output for 5.5.29
<pre>Avg time: 0.01011227 Avg time: 0.00305730 Difference: 0.00705497 Ratio: 3.30758553
Output for 5.5.28
<pre>Avg time: 0.01293405 Avg time: 0.00356463 Difference: 0.00936942 Ratio: 3.62844037
Output for 5.5.27
<pre>Avg time: 0.01006421 Avg time: 0.00306544 Difference: 0.00699877 Ratio: 3.28312222
Output for 5.5.26
<pre>Avg time: 0.01060821 Avg time: 0.00301707 Difference: 0.00759115 Ratio: 3.51606701
Output for 5.5.25
<pre>Avg time: 0.01054992 Avg time: 0.00294297 Difference: 0.00760695 Ratio: 3.58478272
Output for 5.5.24
<pre>Avg time: 0.01205112 Avg time: 0.00267329 Difference: 0.00937783 Ratio: 4.50797452
Output for 5.4.45
<pre>Avg time: 0.01074268 Avg time: 0.00313886 Difference: 0.00760382 Ratio: 3.42247675
Output for 5.4.44
<pre>Avg time: 0.01067345 Avg time: 0.00312845 Difference: 0.00754500 Ratio: 3.41173539
Output for 5.4.43
<pre>Avg time: 0.01442791 Avg time: 0.00461876 Difference: 0.00980916 Ratio: 3.12376584
Output for 5.4.42
<pre>Avg time: 0.01079525 Avg time: 0.00315094 Difference: 0.00764431 Ratio: 3.42604268
Output for 5.4.41
<pre>Avg time: 0.01271879 Avg time: 0.00344207 Difference: 0.00927672 Ratio: 3.69509853
Output for 5.4.40
<pre>Avg time: 0.01034405 Avg time: 0.00314094 Difference: 0.00720311 Ratio: 3.29329933
Output for 5.4.39
<pre>Avg time: 0.01070739 Avg time: 0.00324980 Difference: 0.00745759 Ratio: 3.29478176
Output for 5.4.38
<pre>Avg time: 0.01364594 Avg time: 0.00422682 Difference: 0.00941912 Ratio: 3.22842082
Output for 5.4.37
<pre>Avg time: 0.01033170 Avg time: 0.00328593 Difference: 0.00704577 Ratio: 3.14422309
Output for 5.4.36
<pre>Avg time: 0.01035622 Avg time: 0.00330069 Difference: 0.00705552 Ratio: 3.13758848
Output for 5.4.35
<pre>Avg time: 0.01435760 Avg time: 0.00418248 Difference: 0.01017512 Ratio: 3.43279837
Output for 5.4.34
<pre>Avg time: 0.01054344 Avg time: 0.00323441 Difference: 0.00730903 Ratio: 3.25977012
Output for 5.4.32
<pre>Avg time: 0.01022738 Avg time: 0.00323955 Difference: 0.00698783 Ratio: 3.15704052
Output for 5.4.31
<pre>Avg time: 0.01021930 Avg time: 0.00322250 Difference: 0.00699680 Ratio: 3.17123541
Output for 5.4.30
<pre>Avg time: 0.01101105 Avg time: 0.00326185 Difference: 0.00774920 Ratio: 3.37570955
Output for 5.4.29
<pre>Avg time: 0.01441517 Avg time: 0.00434606 Difference: 0.01006912 Ratio: 3.31683846
Output for 5.4.28
<pre>Avg time: 0.01006712 Avg time: 0.00318506 Difference: 0.00688207 Ratio: 3.16073774
Output for 5.4.27
<pre>Avg time: 0.00996132 Avg time: 0.00323486 Difference: 0.00672646 Ratio: 3.07936321
Output for 5.4.26
<pre>Avg time: 0.01024520 Avg time: 0.00314930 Difference: 0.00709590 Ratio: 3.25316902
Output for 5.4.25
<pre>Avg time: 0.01055085 Avg time: 0.00330855 Difference: 0.00724230 Ratio: 3.18896812
Output for 5.4.24
<pre>Avg time: 0.01050737 Avg time: 0.00321147 Difference: 0.00729590 Ratio: 3.27182236
Output for 5.4.23
<pre>Avg time: 0.01040486 Avg time: 0.00316354 Difference: 0.00724132 Ratio: 3.28898941
Output for 5.4.22
<pre>Avg time: 0.01025189 Avg time: 0.00316650 Difference: 0.00708539 Ratio: 3.23760755
Output for 5.4.21
<pre>Avg time: 0.01068236 Avg time: 0.00317312 Difference: 0.00750924 Ratio: 3.36651732
Output for 5.4.20
<pre>Avg time: 0.01039634 Avg time: 0.00317068 Difference: 0.00722567 Ratio: 3.27890378
Output for 5.4.19
<pre>Avg time: 0.01037859 Avg time: 0.00333244 Difference: 0.00704615 Ratio: 3.11441449
Output for 5.4.18
<pre>Avg time: 0.01083792 Avg time: 0.00320560 Difference: 0.00763233 Ratio: 3.38093928
Output for 5.4.17
<pre>Avg time: 0.01026559 Avg time: 0.00314978 Difference: 0.00711581 Ratio: 3.25914664
Output for 5.4.16
<pre>Avg time: 0.01571377 Avg time: 0.00464338 Difference: 0.01107039 Ratio: 3.38412108
Output for 5.4.15
<pre>Avg time: 0.01076852 Avg time: 0.00313395 Difference: 0.00763457 Ratio: 3.43608655
Output for 5.4.14
<pre>Avg time: 0.01083737 Avg time: 0.00331447 Difference: 0.00752290 Ratio: 3.26971277
Output for 5.4.13
<pre>Avg time: 0.01444347 Avg time: 0.00411127 Difference: 0.01033220 Ratio: 3.51314378
Output for 5.4.12
<pre>Avg time: 0.01055340 Avg time: 0.00315967 Difference: 0.00739373 Ratio: 3.34003667
Output for 5.4.11
<pre>Avg time: 0.01042239 Avg time: 0.00320464 Difference: 0.00721775 Ratio: 3.25228365
Output for 5.4.10
<pre>Avg time: 0.01046177 Avg time: 0.00339989 Difference: 0.00706188 Ratio: 3.07709235
Output for 5.4.9
<pre>Avg time: 0.01058702 Avg time: 0.00330106 Difference: 0.00728596 Ratio: 3.20715661
Output for 5.4.8
<pre>Avg time: 0.01056734 Avg time: 0.00330060 Difference: 0.00726674 Ratio: 3.20164002
Output for 5.4.7
<pre>Avg time: 0.01054245 Avg time: 0.00334612 Difference: 0.00719633 Ratio: 3.15064704
Output for 5.4.6
<pre>Avg time: 0.01010051 Avg time: 0.00316573 Difference: 0.00693478 Ratio: 3.19057618
Output for 5.4.5
<pre>Avg time: 0.00983778 Avg time: 0.00312960 Difference: 0.00670818 Ratio: 3.14345930
Output for 5.4.4
<pre>Avg time: 0.01037322 Avg time: 0.00314742 Difference: 0.00722580 Ratio: 3.29578260
Output for 5.4.3
<pre>Avg time: 0.01340185 Avg time: 0.00407117 Difference: 0.00933068 Ratio: 3.29189416
Output for 5.4.2
<pre>Avg time: 0.01072932 Avg time: 0.00313936 Difference: 0.00758996 Ratio: 3.41767863
Output for 5.4.1
<pre>Avg time: 0.01054636 Avg time: 0.00313951 Difference: 0.00740684 Ratio: 3.35923336
Output for 5.4.0
<pre>Avg time: 0.01053457 Avg time: 0.00319466 Difference: 0.00733991 Ratio: 3.29755727
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/lDY2B on line 6
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/lDY2B on line 6
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/lDY2B on line 6
Process exited with code 255.