3v4l.org

run code in 300+ PHP versions simultaneously
<?php function utime() { list($usec, $sec) = explode(" ",microtime()); return ((float)$usec + (float)$sec); } $loop=10000; $cases = array('best case'=> 'a', 'worst case'=> 'z'); $ar = array('a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'); foreach($cases as $case => $x){ $a = utime(); for($i=0;$i<$loop; $i++){ $result = ($x == 'a' || $x == 'b' || $x == 'c' || $x == 'd' || $x == 'e' || $x == 'f' || $x == 'g' || $x == 'h' || $x == 'i' || $x == 'j' || $x == 'k' || $x == 'l' || $x == 'm' || $x == 'n' || $x == 'o' || $x == 'p' || $x == 'q' || $x == 'r' || $x == 's' || $x == 't' || $x == 'u' || $x == 'v' || $x == 'w' || $x == 'x' || $x == 'y' || $x == 'z'); } $b = utime(); for($i=0;$i<$loop; $i++){ $result = in_array($x, $ar); } $c = utime(); printf("%-25s = %s\n", "$case in_array()", number_format($c-$b, 3)); printf("%-25s = %s\n", "$case logical or", number_format($b-$a, 3)); }

preferences:
33.54 ms | 402 KiB | 5 Q