3v4l.org

run code in 300+ PHP versions simultaneously
<?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);

Abusive script

This script was stopped while abusing our resources

Output for 7.4.0
Avg time: 0.01016856 Avg time: 0.00388739 Difference: 0.00628117 Ratio: 2.61578152
Output for 7.3.12
Avg time: 0.00749088 Avg time: 0.00369376 Difference: 0.00379713 Ratio: 2.02798472
Output for 7.3.11
Avg time: 0.01067449 Avg time: 0.00429989 Difference: 0.00637460 Ratio: 2.48250213
Output for 7.3.10
Avg time: 0.01037790 Avg time: 0.00436786 Difference: 0.00601003 Ratio: 2.37596711
Output for 7.3.9
Avg time: 0.00707312 Avg time: 0.00360252 Difference: 0.00347060 Ratio: 1.96337941
Output for 7.3.8
Avg time: 0.01003400 Avg time: 0.00413322 Difference: 0.00590078 Ratio: 2.42764759
Output for 7.3.7
Avg time: 0.00996393 Avg time: 0.00364908 Difference: 0.00631486 Ratio: 2.73053522
Output for 7.3.6
Avg time: 0.00775527 Avg time: 0.00413772 Difference: 0.00361755 Ratio: 1.87428485
Output for 7.3.5
Avg time: 0.00977209 Avg time: 0.00394015 Difference: 0.00583194 Ratio: 2.48013184
Output for 7.3.4
Avg time: 0.00690017 Avg time: 0.00394107 Difference: 0.00295910 Ratio: 1.75083832
Output for 7.3.3
Avg time: 0.00813949 Avg time: 0.00412476 Difference: 0.00401473 Ratio: 1.97332275
Output for 7.3.2
Avg time: 0.00884851 Avg time: 0.00366937 Difference: 0.00517913 Ratio: 2.41144812
Output for 7.3.1
Avg time: 0.00874643 Avg time: 0.00368368 Difference: 0.00506275 Ratio: 2.37437397
Output for 7.3.0
Avg time: 0.00816127 Avg time: 0.00265759 Difference: 0.00550368 Ratio: 3.07092926
Output for 7.2.25
Avg time: 0.01121327 Avg time: 0.00467262 Difference: 0.00654065 Ratio: 2.39978427
Output for 7.2.24
Avg time: 0.00737521 Avg time: 0.00364402 Difference: 0.00373119 Ratio: 2.02392089
Output for 7.2.23
Avg time: 0.01177503 Avg time: 0.00444157 Difference: 0.00733346 Ratio: 2.65109532
Output for 7.2.22
Avg time: 0.01118252 Avg time: 0.00424227 Difference: 0.00694026 Ratio: 2.63597769
Output for 7.2.21
Avg time: 0.00886664 Avg time: 0.00380918 Difference: 0.00505746 Ratio: 2.32770560
Output for 7.2.20
Avg time: 0.01126388 Avg time: 0.00452126 Difference: 0.00674262 Ratio: 2.49131649
Output for 7.2.19
Avg time: 0.00758881 Avg time: 0.00380624 Difference: 0.00378257 Ratio: 1.99378059
Output for 7.2.18
Avg time: 0.01003820 Avg time: 0.00375797 Difference: 0.00628023 Ratio: 2.67117644
Output for 7.2.17
Avg time: 0.00727634 Avg time: 0.00429055 Difference: 0.00298579 Ratio: 1.69589950
Output for 7.2.16
Avg time: 0.01160301 Avg time: 0.00450097 Difference: 0.00710205 Ratio: 2.57789370
Output for 7.2.15
Avg time: 0.01040166 Avg time: 0.00373860 Difference: 0.00666306 Ratio: 2.78223347
Output for 7.2.14
Avg time: 0.00775746 Avg time: 0.00330283 Difference: 0.00445463 Ratio: 2.34872967
Output for 7.2.13
Avg time: 0.00743376 Avg time: 0.00320151 Difference: 0.00423225 Ratio: 2.32195298
Output for 7.2.12
Avg time: 0.01037262 Avg time: 0.00352455 Difference: 0.00684807 Ratio: 2.94296035
Output for 7.2.11
Avg time: 0.00823116 Avg time: 0.00631672 Difference: 0.00191444 Ratio: 1.30307470
Output for 7.2.10
Avg time: 0.00572129 Avg time: 0.00295580 Difference: 0.00276549 Ratio: 1.93561384
Output for 7.2.9
Avg time: 0.00687505 Avg time: 0.00272009 Difference: 0.00415496 Ratio: 2.52750660
Output for 7.2.8
Avg time: 0.00571742 Avg time: 0.00273290 Difference: 0.00298452 Ratio: 2.09207335
Output for 7.2.7
Avg time: 0.00724795 Avg time: 0.00269245 Difference: 0.00455550 Ratio: 2.69195533
Output for 7.2.6
Avg time: 0.00686677 Avg time: 0.00280136 Difference: 0.00406541 Ratio: 2.45122918
Output for 7.2.5
Avg time: 0.00725645 Avg time: 0.00300508 Difference: 0.00425137 Ratio: 2.41472618
Output for 7.2.4
Avg time: 0.00775475 Avg time: 0.00292114 Difference: 0.00483361 Ratio: 2.65469979
Output for 7.2.3
Avg time: 0.00665032 Avg time: 0.00449888 Difference: 0.00215143 Ratio: 1.47821532
Output for 7.2.2
Avg time: 0.00579744 Avg time: 0.00275301 Difference: 0.00304443 Ratio: 2.10585835
Output for 7.2.1
Avg time: 0.00966252 Avg time: 0.00311656 Difference: 0.00654596 Ratio: 3.10038342
Output for 7.2.0
Avg time: 0.00692018 Avg time: 0.00276743 Difference: 0.00415275 Ratio: 2.50058066
Output for 7.1.33
Avg time: 0.00834404 Avg time: 0.00466152 Difference: 0.00368252 Ratio: 1.78998151
Output for 7.1.32
Avg time: 0.00947777 Avg time: 0.00607333 Difference: 0.00340443 Ratio: 1.56055432
Output for 7.1.31
Avg time: 0.01272051 Avg time: 0.00438424 Difference: 0.00833627 Ratio: 2.90141896
Output for 7.1.30
Avg time: 0.01177791 Avg time: 0.00600584 Difference: 0.00577207 Ratio: 1.96107552
Output for 7.1.29
Avg time: 0.01203809 Avg time: 0.00551288 Difference: 0.00652520 Ratio: 2.18362770
Output for 7.1.28
Avg time: 0.00792208 Avg time: 0.00472564 Difference: 0.00319643 Ratio: 1.67640190
Output for 7.1.27
Avg time: 0.00891505 Avg time: 0.00689865 Difference: 0.00201640 Ratio: 1.29228862
Output for 7.1.26
Avg time: 0.01114292 Avg time: 0.00596036 Difference: 0.00518256 Ratio: 1.86950456
Output for 7.1.25
Avg time: 0.01255870 Avg time: 0.00601048 Difference: 0.00654822 Ratio: 2.08946766
Output for 7.1.24
Avg time: 0.01170644 Avg time: 0.00461634 Difference: 0.00709010 Ratio: 2.53586884
Output for 7.1.23
Avg time: 0.01016333 Avg time: 0.00422359 Difference: 0.00593973 Ratio: 2.40632277
Output for 7.1.22
Avg time: 0.01095129 Avg time: 0.00420714 Difference: 0.00674415 Ratio: 2.60302402
Output for 7.1.21
Avg time: 0.00909925 Avg time: 0.00423772 Difference: 0.00486153 Ratio: 2.14720363
Output for 7.1.20
Avg time: 0.00873302 Avg time: 0.00515344 Difference: 0.00357958 Ratio: 1.69460007
Output for 7.1.19
Avg time: 0.00916303 Avg time: 0.00451506 Difference: 0.00464797 Ratio: 2.02943731
Output for 7.1.18
Avg time: 0.00939464 Avg time: 0.00437638 Difference: 0.00501826 Ratio: 2.14667033
Output for 7.1.17
Avg time: 0.00806006 Avg time: 0.00479363 Difference: 0.00326643 Ratio: 1.68141057
Output for 7.1.16
Avg time: 0.00835698 Avg time: 0.00431956 Difference: 0.00403742 Ratio: 1.93468160
Output for 7.1.15
Avg time: 0.00685748 Avg time: 0.00499551 Difference: 0.00186197 Ratio: 1.37272911
Output for 7.1.14
Avg time: 0.00933503 Avg time: 0.00444875 Difference: 0.00488628 Ratio: 2.09834872
Output for 7.1.13
Avg time: 0.00779438 Avg time: 0.00497459 Difference: 0.00281979 Ratio: 1.56683844
Output for 7.1.12
Avg time: 0.00875365 Avg time: 0.00410692 Difference: 0.00464673 Ratio: 2.13143864
Output for 7.1.11
Avg time: 0.00762728 Avg time: 0.00490794 Difference: 0.00271935 Ratio: 1.55407090
Output for 7.1.10
Avg time: 0.00688447 Avg time: 0.00413649 Difference: 0.00274797 Ratio: 1.66432465
Output for 7.1.9
Avg time: 0.01034939 Avg time: 0.00446564 Difference: 0.00588376 Ratio: 2.31756240
Output for 7.1.8
Avg time: 0.01011369 Avg time: 0.00461378 Difference: 0.00549990 Ratio: 2.19205896
Output for 7.1.7
Avg time: 0.00680552 Avg time: 0.00414925 Difference: 0.00265628 Ratio: 1.64018284
Output for 7.1.6
Avg time: 0.00739207 Avg time: 0.00447817 Difference: 0.00291390 Ratio: 1.65069053
Output for 7.1.5
Avg time: 0.00628637 Avg time: 0.00414922 Difference: 0.00213716 Ratio: 1.51507434
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.1.0, 7.1.4

Process exited with code 137.
Output for 7.1.3
Avg time: 0.00695192 Avg time: 0.00487561 Difference: 0.00207631 Ratio: 1.42585649
Output for 7.1.2
Avg time: 0.00830521 Avg time: 0.00406744 Difference: 0.00423777 Ratio: 2.04187671
Output for 7.1.1
Avg time: 0.00606935 Avg time: 0.00441884 Difference: 0.00165051 Ratio: 1.37351617
Output for 7.0.33
Avg time: 0.00532424 Avg time: 0.00274241 Difference: 0.00258183 Ratio: 1.94144490
Output for 7.0.32
Avg time: 0.00623774 Avg time: 0.00239424 Difference: 0.00384349 Ratio: 2.60530422
Output for 7.0.31
Avg time: 0.00619142 Avg time: 0.00265625 Difference: 0.00353517 Ratio: 2.33088684
Output for 7.0.30
Avg time: 0.00879425 Avg time: 0.00387285 Difference: 0.00492140 Ratio: 2.27074331
Output for 7.0.29
Avg time: 0.00763997 Avg time: 0.00273112 Difference: 0.00490885 Ratio: 2.79737585
Output for 7.0.28
Avg time: 0.00553808 Avg time: 0.00302041 Difference: 0.00251767 Ratio: 1.83355199
Output for 7.0.27
Avg time: 0.00696091 Avg time: 0.00244901 Difference: 0.00451189 Ratio: 2.84233020
Output for 7.0.26
Avg time: 0.00651477 Avg time: 0.00271907 Difference: 0.00379571 Ratio: 2.39595987
Output for 7.0.25
Avg time: 0.00465142 Avg time: 0.00239042 Difference: 0.00226101 Ratio: 1.94586446
Output for 7.0.24
Avg time: 0.00503096 Avg time: 0.00291653 Difference: 0.00211443 Ratio: 1.72498306
Output for 7.0.23
Avg time: 0.00492803 Avg time: 0.00252541 Difference: 0.00240262 Ratio: 1.95137902
Output for 7.0.22
Avg time: 0.00877235 Avg time: 0.00282812 Difference: 0.00594424 Ratio: 3.10183544
Output for 7.0.21
Avg time: 0.00487881 Avg time: 0.00253650 Difference: 0.00234230 Ratio: 1.92343736
Output for 7.0.20
Avg time: 0.00535203 Avg time: 0.00234593 Difference: 0.00300611 Ratio: 2.28141588
Output for 7.0.19
Avg time: 0.00619767 Avg time: 0.00251798 Difference: 0.00367969 Ratio: 2.46136650
Output for 7.0.18
Avg time: 0.00699620 Avg time: 0.00387856 Difference: 0.00311764 Ratio: 1.80381316
Output for 7.0.17
Avg time: 0.00628209 Avg time: 0.00268435 Difference: 0.00359774 Ratio: 2.34026112
Output for 7.0.16
Avg time: 0.00496407 Avg time: 0.00239880 Difference: 0.00256527 Ratio: 2.06939560
Output for 7.0.15
Avg time: 0.00495002 Avg time: 0.00238603 Difference: 0.00256399 Ratio: 2.07458634
Output for 7.0.14
Avg time: 0.00528073 Avg time: 0.00236223 Difference: 0.00291851 Ratio: 2.23549111
Output for 7.0.13
Avg time: 0.00524282 Avg time: 0.00250650 Difference: 0.00273632 Ratio: 2.09169003
Output for 7.0.12
Avg time: 0.00471531 Avg time: 0.00268714 Difference: 0.00202817 Ratio: 1.75476678
Output for 7.0.11
Avg time: 0.00481187 Avg time: 0.00235147 Difference: 0.00246041 Ratio: 2.04632776
Output for 7.0.10
Avg time: 0.00574429 Avg time: 0.00392228 Difference: 0.00182200 Ratio: 1.46452669
Output for 7.0.9
Avg time: 0.00467904 Avg time: 0.00245297 Difference: 0.00222607 Ratio: 1.90750149
Output for 7.0.8
Avg time: 0.00710608 Avg time: 0.00247570 Difference: 0.00463038 Ratio: 2.87032844
Output for 7.0.7
Avg time: 0.00619453 Avg time: 0.00239253 Difference: 0.00380200 Ratio: 2.58911211
Output for 7.0.6
Avg time: 0.01260624 Avg time: 0.00262083 Difference: 0.00998541 Ratio: 4.81001878
Output for 7.0.5
Avg time: 0.00912639 Avg time: 0.00261624 Difference: 0.00651015 Ratio: 3.48836175
Output for 7.0.4
Avg time: 0.00953227 Avg time: 0.00258101 Difference: 0.00695126 Ratio: 3.69323101
Output for 7.0.3
Avg time: 0.00979274 Avg time: 0.00244820 Difference: 0.00734454 Ratio: 3.99997078
Output for 7.0.2
Avg time: 0.01426979 Avg time: 0.00238393 Difference: 0.01188586 Ratio: 5.98583147
Output for 7.0.1
Avg time: 0.00905829 Avg time: 0.00272844 Difference: 0.00632985 Ratio: 3.31994806
Output for 7.0.0
Avg time: 0.01088082 Avg time: 0.00242731 Difference: 0.00845351 Ratio: 4.48266456

preferences:
202.93 ms | 401 KiB | 239 Q