3v4l.org

run code in 300+ PHP versions simultaneously
<?php $a=str_split(str_repeat("a",99999)); $pre_best = PHP_INT_MAX; $post_best = PHP_INT_MAX; for($i=0;$i<99;++$i){ $t=microtime(true); array_is_list_pre($a); $t=microtime(true)-$t; if($t < $pre_best){ $pre_best = $t; } } for($i=0;$i<99;++$i){ $t=microtime(true); array_is_list_post($a); $t=microtime(true)-$t; if($t < $post_best){ $post_best = $t; } } if($pre_best===$post_best){ echo "it's a tie!"; }elseif($pre_best<$post_best){ echo "pre won!"; }else{ echo "post won!"; } var_dump($pre_best,$post_best); function array_is_list_pre(array $array): bool { $i = 0; foreach ($array as $k => $v) { if ($k !== $i) { return false; } ++$i; } return true; } function array_is_list_post(array $array): bool { $i = 0; foreach ($array as $k => $v) { if ($k !== $i++) { return false; } } return true; }

preferences:
23.58 ms | 407 KiB | 5 Q