3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php // 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 lDY2B
Output for 7.1.0
Avg time: -0.00033641 Avg time: 0.01025352 Difference: -0.01058993 Ratio: -0.03280907
Output for 7.0.14
Avg time: 0.00455563 Avg time: -0.00085914 Difference: 0.00541477 Ratio: -5.30251893
Output for 7.0.6
Avg time: 0.00558531 Avg time: 0.00093500 Difference: 0.00465031 Ratio: 5.97361066
Output for 7.0.5
Avg time: 0.00521148 Avg time: 0.00117557 Difference: 0.00403592 Ratio: 4.43316946
Output for 7.0.4
Avg time: 0.00541787 Avg time: 0.00093014 Difference: 0.00448773 Ratio: 5.82481602
Output for 7.0.3
Avg time: 0.00559800 Avg time: 0.00093154 Difference: 0.00466645 Ratio: 6.00937249
Output for 7.0.2
Avg time: 0.00534143 Avg time: 0.00094365 Difference: 0.00439778 Ratio: 5.66041426
Output for 7.0.1
Avg time: 0.00527621 Avg time: 0.00093469 Difference: 0.00434151 Ratio: 5.64486351
Output for 7.0.0
Avg time: 0.00767043 Avg time: 0.00112062 Difference: 0.00654981 Ratio: 6.84480726
Output for 5.6.28
Avg time: 0.01148088 Avg time: 0.00298317 Difference: 0.00849770 Ratio: 3.84854392
Output for 5.6.21
Avg time: 0.01173271 Avg time: 0.00304340 Difference: 0.00868931 Ratio: 3.85513222
Output for 5.6.20
Avg time: 0.01204775 Avg time: 0.00296818 Difference: 0.00907958 Ratio: 4.05897293
Output for 5.6.19
Avg time: 0.01156972 Avg time: 0.00298669 Difference: 0.00858303 Ratio: 3.87375839
Output for 5.6.18
Avg time: 0.01123884 Avg time: 0.00311764 Difference: 0.00812120 Ratio: 3.60492249
Output for 5.6.17
Avg time: 0.01161903 Avg time: 0.00295349 Difference: 0.00866555 Ratio: 3.93400614
Output for 5.6.16
Avg time: 0.01162051 Avg time: 0.00293838 Difference: 0.00868214 Ratio: 3.95473794
Output for 5.6.15
Avg time: 0.01129660 Avg time: 0.00291540 Difference: 0.00838120 Ratio: 3.87480526
Output for 5.6.14
Avg time: 0.01161218 Avg time: 0.00304236 Difference: 0.00856982 Ratio: 3.81683734
Output for 5.6.13
Avg time: 0.01134926 Avg time: 0.00295990 Difference: 0.00838936 Ratio: 3.83433550
Output for 5.6.12
Avg time: 0.01143729 Avg time: 0.00291958 Difference: 0.00851772 Ratio: 3.91744947
Output for 5.6.11
Avg time: 0.01179714 Avg time: 0.00292292 Difference: 0.00887422 Ratio: 4.03607695
Output for 5.6.10
Avg time: 0.01139596 Avg time: 0.00305945 Difference: 0.00833651 Ratio: 3.72484036
Output for 5.6.9
Avg time: 0.01107985 Avg time: 0.00291625 Difference: 0.00816360 Ratio: 3.79934514
Output for 5.6.8
Avg time: 0.01164525 Avg time: 0.00291926 Difference: 0.00872599 Ratio: 3.98910512
Output for 5.5.35
Avg time: 0.01059357 Avg time: 0.00272493 Difference: 0.00786864 Ratio: 3.88764393
Output for 5.5.34
Avg time: 0.01066900 Avg time: 0.00303747 Difference: 0.00763153 Ratio: 3.51245870
Output for 5.5.33
Avg time: 0.01079379 Avg time: 0.00300174 Difference: 0.00779205 Ratio: 3.59584963
Output for 5.5.32
Avg time: 0.01133711 Avg time: 0.00302697 Difference: 0.00831014 Ratio: 3.74536765
Output for 5.5.31
Avg time: 0.01039045 Avg time: 0.00306784 Difference: 0.00732261 Ratio: 3.38689113
Output for 5.5.30
Avg time: 0.01062153 Avg time: 0.00304304 Difference: 0.00757849 Ratio: 3.49043010
Output for 5.5.29
Avg time: 0.01046267 Avg time: 0.00303807 Difference: 0.00742459 Ratio: 3.44384785
Output for 5.5.28
Avg time: 0.01048800 Avg time: 0.00323521 Difference: 0.00725279 Ratio: 3.24183073
Output for 5.5.27
Avg time: 0.01041295 Avg time: 0.00306309 Difference: 0.00734986 Ratio: 3.39948893
Output for 5.5.26
Avg time: 0.01059518 Avg time: 0.00305886 Difference: 0.00753632 Ratio: 3.46376483
Output for 5.5.25
Avg time: 0.01070687 Avg time: 0.00304018 Difference: 0.00766670 Ratio: 3.52179167
Output for 5.5.24
Avg time: 0.01046565 Avg time: 0.00264122 Difference: 0.00782443 Ratio: 3.96242941
Output for 5.4.45
Avg time: 0.01068065 Avg time: 0.00330990 Difference: 0.00737075 Ratio: 3.22687740
Output for 5.4.44
Avg time: 0.01058195 Avg time: 0.00316267 Difference: 0.00741928 Ratio: 3.34588646
Output for 5.4.43
Avg time: 0.01091752 Avg time: 0.00318922 Difference: 0.00772830 Ratio: 3.42325861
Output for 5.4.42
Avg time: 0.01352989 Avg time: 0.00412829 Difference: 0.00940161 Ratio: 3.27736295
Output for 5.4.41
Avg time: 0.01097703 Avg time: 0.00318036 Difference: 0.00779667 Ratio: 3.45150715
Output for 5.4.40
Avg time: 0.01729092 Avg time: 0.00405907 Difference: 0.01323185 Ratio: 4.25982616
Output for 5.4.39
Avg time: 0.01030519 Avg time: 0.00325550 Difference: 0.00704969 Ratio: 3.16546926
Output for 5.4.38
Avg time: 0.01054151 Avg time: 0.00321768 Difference: 0.00732384 Ratio: 3.27612662
Output for 5.4.37
Avg time: 0.01067017 Avg time: 0.00327789 Difference: 0.00739228 Ratio: 3.25519276
Output for 5.4.36
Avg time: 0.01089638 Avg time: 0.00328441 Difference: 0.00761197 Ratio: 3.31760432
Output for 5.4.35
Avg time: 0.01116926 Avg time: 0.00322838 Difference: 0.00794088 Ratio: 3.45971287
Output for 5.4.34
Avg time: 0.01052355 Avg time: 0.00326056 Difference: 0.00726300 Ratio: 3.22753161
Output for 5.4.24, 5.4.32

Process exited with code 137.
Output for 5.4.31
Avg time: 0.01208271 Avg time: 0.00384373 Difference: 0.00823899 Ratio: 3.14348868
Output for 5.4.30
Avg time: 0.01188489 Avg time: 0.00429624 Difference: 0.00758865 Ratio: 2.76634526
Output for 5.4.29
Avg time: 0.01229704 Avg time: 0.00368319 Difference: 0.00861385 Ratio: 3.33869440
Output for 5.4.28
Avg time: 0.01303874 Avg time: 0.00380275 Difference: 0.00923599 Ratio: 3.42877027
Output for 5.4.27
Avg time: 0.01335668 Avg time: 0.00566088 Difference: 0.00769580 Ratio: 2.35947192
Output for 5.4.26
Avg time: 0.01338420 Avg time: 0.00461571 Difference: 0.00876849 Ratio: 2.89970604
Output for 5.4.25
Avg time: 0.01460948 Avg time: 0.00444854 Difference: 0.01016094 Ratio: 3.28410598
Output for 5.4.23
Avg time: 0.01017611 Avg time: 0.00318550 Difference: 0.00699061 Ratio: 3.19451162
Output for 5.4.22
Avg time: 0.01029335 Avg time: 0.00329548 Difference: 0.00699786 Ratio: 3.12347113
Output for 5.4.21
Avg time: 0.01075282 Avg time: 0.00317987 Difference: 0.00757295 Ratio: 3.38152960
Output for 5.4.20
Avg time: 0.01077046 Avg time: 0.00315739 Difference: 0.00761307 Ratio: 3.41119047
Output for 5.4.19
Avg time: 0.01048916 Avg time: 0.00320735 Difference: 0.00728181 Ratio: 3.27034828
Output for 5.4.18
Avg time: 0.01022080 Avg time: 0.00316413 Difference: 0.00705667 Ratio: 3.23021088
Output for 5.4.17
Avg time: 0.01205312 Avg time: 0.00355611 Difference: 0.00849701 Ratio: 3.38941363
Output for 5.4.16
Avg time: 0.01338088 Avg time: 0.00453742 Difference: 0.00884346 Ratio: 2.94900874
Output for 5.4.15
Avg time: 0.01095748 Avg time: 0.00317980 Difference: 0.00777768 Ratio: 3.44596260
Output for 5.4.14
Avg time: 0.01058519 Avg time: 0.00313293 Difference: 0.00745227 Ratio: 3.37869099
Output for 5.4.13
Avg time: 0.01039769 Avg time: 0.00316782 Difference: 0.00722988 Ratio: 3.28229112
Output for 5.4.12
Avg time: 0.01077213 Avg time: 0.00314898 Difference: 0.00762314 Ratio: 3.42082557
Output for 5.4.11
Avg time: 0.01047574 Avg time: 0.00316720 Difference: 0.00730853 Ratio: 3.30756492
Output for 5.4.10
Avg time: 0.01081518 Avg time: 0.00334976 Difference: 0.00746542 Ratio: 3.22864258
Output for 5.4.9
Avg time: 0.01060693 Avg time: 0.00353653 Difference: 0.00707040 Ratio: 2.99925033
Output for 5.4.8
Avg time: 0.01059879 Avg time: 0.00332531 Difference: 0.00727348 Ratio: 3.18730628
Output for 5.4.7
Avg time: 0.01038550 Avg time: 0.00324818 Difference: 0.00713732 Ratio: 3.19733130
Output for 5.4.6
Avg time: 0.01007212 Avg time: 0.00316830 Difference: 0.00690382 Ratio: 3.17903272
Output for 5.4.5
Avg time: 0.01030519 Avg time: 0.00312069 Difference: 0.00718450 Ratio: 3.30221665
Output for 5.4.4
Avg time: 0.01115539 Avg time: 0.00313034 Difference: 0.00802505 Ratio: 3.56363755
Output for 5.4.3
Avg time: 0.01092612 Avg time: 0.00317009 Difference: 0.00775602 Ratio: 3.44662215
Output for 5.4.2
Avg time: 0.01190608 Avg time: 0.00334940 Difference: 0.00855667 Ratio: 3.55468515
Output for 5.4.1
Avg time: 0.01049268 Avg time: 0.00314998 Difference: 0.00734270 Ratio: 3.33103340
Output for 5.4.0
Avg time: 0.01065459 Avg time: 0.00319064 Difference: 0.00746395 Ratio: 3.33933047
Output for 5.3.9 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/NYBlh on line 4
Process exited with code 255.