3v4l.org

run code in 300+ PHP versions simultaneously
#!/usr/bin/php <?php declare(strict_types=1); const ITERATIONS = 100000; $results = array(); for ($i = 0; $i < ITERATIONS; ++$i) { // heat up cpu (if it was powersaving-running-low-cus-nothing-was-happening, most modern cpus try to do it by default) } function array_is_list_post(array $array): bool { $i = 0; foreach ($array as $k => $v) { if ($k !== $i++) { return false; } } return true; } function array_is_list_pre(array $array): bool { $i = -1; foreach ($array as $k => $v) { ++$i; if ($k !== $i) { return false; } } return true; } $l1 = str_split(str_repeat("A", 300), 1); $t = microtime(true); for ($i = 0; $i < ITERATIONS; ++$i) { array_is_list_pre($l1); } $t = microtime(true) - $t; $results["pre"] = $t; $t = microtime(true); for ($i = 0; $i < ITERATIONS; ++$i) { array_is_list_post($l1); } $t = microtime(true) - $t; $results["post"] = $t; if ($results["pre"] === $results["post"]) { echo "it's a tie!"; } elseif ($results["pre"] < $results["post"]) { echo "pre is faster!"; } else { echo "post is faster!"; } echo "diff: " . abs(($results["pre"] - $results["post"])) . "\n"; var_dump($results); exit();
Output for 8.1.7
pre is faster!diff: 0.045486927032471 array(2) { ["pre"]=> float(0.41790294647216797) ["post"]=> float(0.46338987350463867) }
Output for 8.1.6
pre is faster!diff: 0.011034965515137 array(2) { ["pre"]=> float(0.44454002380371094) ["post"]=> float(0.45557498931884766) }
Output for 8.1.5
pre is faster!diff: 0.032110929489136 array(2) { ["pre"]=> float(0.4264960289001465) ["post"]=> float(0.4586069583892822) }
Output for 8.1.4
pre is faster!diff: 0.026257991790771 array(2) { ["pre"]=> float(0.4231750965118408) ["post"]=> float(0.4494330883026123) }
Output for 8.1.3
pre is faster!diff: 0.024855136871338 array(2) { ["pre"]=> float(0.43219780921936035) ["post"]=> float(0.45705294609069824) }
Output for 8.1.2
pre is faster!diff: 0.028049945831299 array(2) { ["pre"]=> float(0.4351999759674072) ["post"]=> float(0.46324992179870605) }
Output for 8.1.1
pre is faster!diff: 0.049229860305786 array(2) { ["pre"]=> float(0.4267690181732178) ["post"]=> float(0.4759988784790039) }
Output for 8.1.0
pre is faster!diff: 0.048060894012451 array(2) { ["pre"]=> float(0.42044615745544434) ["post"]=> float(0.4685070514678955) }
Output for 8.0.20
pre is faster!diff: 0.031369209289551 array(2) { ["pre"]=> float(0.4630718231201172) ["post"]=> float(0.49444103240966797) }
Output for 8.0.19
pre is faster!diff: 0.029937982559204 array(2) { ["pre"]=> float(0.47332286834716797) ["post"]=> float(0.5032608509063721) }
Output for 8.0.18
post is faster!diff: 0.036201953887939 array(2) { ["pre"]=> float(0.52565598487854) ["post"]=> float(0.4894540309906006) }
Output for 8.0.17
pre is faster!diff: 0.0018091201782227 array(2) { ["pre"]=> float(0.4781489372253418) ["post"]=> float(0.47995805740356445) }
Output for 8.0.16
pre is faster!diff: 0.020554065704346 array(2) { ["pre"]=> float(0.4576430320739746) ["post"]=> float(0.4781970977783203) }
Output for 8.0.15
pre is faster!diff: 0.0059740543365479 array(2) { ["pre"]=> float(0.4774050712585449) ["post"]=> float(0.4833791255950928) }
Output for 8.0.14
pre is faster!diff: 0.0101478099823 array(2) { ["pre"]=> float(0.4709501266479492) ["post"]=> float(0.481097936630249) }
Output for 8.0.13
pre is faster!diff: 0.03826904296875 array(2) { ["pre"]=> float(0.4512479305267334) ["post"]=> float(0.4895169734954834) }
Output for 8.0.12
pre is faster!diff: 0.031514167785645 array(2) { ["pre"]=> float(0.4731559753417969) ["post"]=> float(0.5046701431274414) }
Output for 8.0.11
pre is faster!diff: 0.038222074508667 array(2) { ["pre"]=> float(0.44910502433776855) ["post"]=> float(0.48732709884643555) }
Output for 8.0.10
pre is faster!diff: 0.035583257675171 array(2) { ["pre"]=> float(0.45505189895629883) ["post"]=> float(0.4906351566314697) }
Output for 8.0.9
pre is faster!diff: 0.0087449550628662 array(2) { ["pre"]=> float(0.5313689708709717) ["post"]=> float(0.5401139259338379) }
Output for 8.0.8
pre is faster!diff: 0.01883602142334 array(2) { ["pre"]=> float(0.4596529006958008) ["post"]=> float(0.4784889221191406) }
Output for 8.0.7
pre is faster!diff: 0.042156934738159 array(2) { ["pre"]=> float(0.45491600036621094) ["post"]=> float(0.4970729351043701) }
Output for 8.0.6
pre is faster!diff: 0.012880086898804 array(2) { ["pre"]=> float(0.46703600883483887) ["post"]=> float(0.4799160957336426) }
Output for 8.0.5
pre is faster!diff: 0.02262806892395 array(2) { ["pre"]=> float(0.4565560817718506) ["post"]=> float(0.4791841506958008) }
Output for 8.0.3
pre is faster!diff: 0.027101039886475 array(2) { ["pre"]=> float(0.4644451141357422) ["post"]=> float(0.4915461540222168) }
Output for 8.0.2
pre is faster!diff: 0.13675594329834 array(2) { ["pre"]=> float(0.48619890213012695) ["post"]=> float(0.6229548454284668) }
Output for 8.0.1
post is faster!diff: 0.011923789978027 array(2) { ["pre"]=> float(0.5476889610290527) ["post"]=> float(0.5357651710510254) }
Output for 7.4.30
pre is faster!diff: 0.014993190765381 array(2) { ["pre"]=> float(0.53980493545532) ["post"]=> float(0.5547981262207) }
Output for 7.4.29
post is faster!diff: 0.01078200340271 array(2) { ["pre"]=> float(0.51363492012024) ["post"]=> float(0.50285291671753) }
Output for 7.4.28
pre is faster!diff: 0.023723125457764 array(2) { ["pre"]=> float(0.45811295509338) ["post"]=> float(0.48183608055115) }
Output for 7.4.27
pre is faster!diff: 0.029500722885132 array(2) { ["pre"]=> float(0.46114921569824) ["post"]=> float(0.49064993858337) }
Output for 7.4.26
pre is faster!diff: 0.0031981468200684 array(2) { ["pre"]=> float(0.48209190368652) ["post"]=> float(0.48529005050659) }
Output for 7.4.25
pre is faster!diff: 0.043043851852417 array(2) { ["pre"]=> float(0.45331406593323) ["post"]=> float(0.49635791778564) }
Output for 7.4.24
pre is faster!diff: 0.033933877944946 array(2) { ["pre"]=> float(0.4510760307312) ["post"]=> float(0.48500990867615) }
Output for 7.4.23
pre is faster!diff: 0.033362150192261 array(2) { ["pre"]=> float(0.46045184135437) ["post"]=> float(0.49381399154663) }
Output for 7.4.22
pre is faster!diff: 0.025141000747681 array(2) { ["pre"]=> float(0.45795297622681) ["post"]=> float(0.48309397697449) }
Output for 7.4.21
pre is faster!diff: 0.034142017364502 array(2) { ["pre"]=> float(0.44716191291809) ["post"]=> float(0.48130393028259) }
Output for 7.4.20
pre is faster!diff: 0.033545017242432 array(2) { ["pre"]=> float(0.44836688041687) ["post"]=> float(0.4819118976593) }
Output for 7.4.19
pre is faster!diff: 0.036324977874756 array(2) { ["pre"]=> float(0.44909906387329) ["post"]=> float(0.48542404174805) }
Output for 7.4.18
pre is faster!diff: 0.040336847305298 array(2) { ["pre"]=> float(0.44737911224365) ["post"]=> float(0.48771595954895) }
Output for 7.4.16
pre is faster!diff: 0.012197017669678 array(2) { ["pre"]=> float(0.47816801071167) ["post"]=> float(0.49036502838135) }
Output for 7.4.15
pre is faster!diff: 0.0043950080871582 array(2) { ["pre"]=> float(0.48133707046509) ["post"]=> float(0.48573207855225) }
Output for 7.4.14
pre is faster!diff: 0.022418975830078 array(2) { ["pre"]=> float(0.464280128479) ["post"]=> float(0.48669910430908) }
Output for 7.4.13
pre is faster!diff: 0.016499996185303 array(2) { ["pre"]=> float(0.46413397789001) ["post"]=> float(0.48063397407532) }
Output for 7.4.12
post is faster!diff: 0.0122389793396 array(2) { ["pre"]=> float(0.55922794342041) ["post"]=> float(0.54698896408081) }
Output for 7.4.11
post is faster!diff: 0.00044703483581543 array(2) { ["pre"]=> float(0.48273897171021) ["post"]=> float(0.48229193687439) }
Output for 7.4.10
pre is faster!diff: 0.031385898590088 array(2) { ["pre"]=> float(0.45306205749512) ["post"]=> float(0.48444795608521) }
Output for 7.4.9
pre is faster!diff: 0.042624711990356 array(2) { ["pre"]=> float(0.46181607246399) ["post"]=> float(0.50444078445435) }
Output for 7.4.8
pre is faster!diff: 0.025676965713501 array(2) { ["pre"]=> float(0.47273802757263) ["post"]=> float(0.49841499328613) }
Output for 7.4.7
pre is faster!diff: 0.053930997848511 array(2) { ["pre"]=> float(0.4555721282959) ["post"]=> float(0.50950312614441) }
Output for 7.4.6
pre is faster!diff: 0.051695108413696 array(2) { ["pre"]=> float(0.45808386802673) ["post"]=> float(0.50977897644043) }
Output for 7.4.5
pre is faster!diff: 0.0091369152069092 array(2) { ["pre"]=> float(0.48011612892151) ["post"]=> float(0.48925304412842) }
Output for 7.4.4
pre is faster!diff: 0.044811010360718 array(2) { ["pre"]=> float(0.46126198768616) ["post"]=> float(0.50607299804688) }
Output for 7.4.3
pre is faster!diff: 0.0074100494384766 array(2) { ["pre"]=> float(0.47268581390381) ["post"]=> float(0.48009586334229) }
Output for 7.4.2
pre is faster!diff: 0.028160810470581 array(2) { ["pre"]=> float(0.48158407211304) ["post"]=> float(0.50974488258362) }
Output for 7.4.1
pre is faster!diff: 0.029469966888428 array(2) { ["pre"]=> float(0.46077704429626) ["post"]=> float(0.49024701118469) }
Output for 7.4.0
pre is faster!diff: 0.010757923126221 array(2) { ["pre"]=> float(0.46820998191833) ["post"]=> float(0.47896790504456) }

preferences:
38.46 ms | 491 KiB | 5 Q