3v4l.org

run code in 300+ PHP versions simultaneously
<?php $cnt = 100000; echo "range()\n"; $mc = microtime(true); for($x=0; $x<=$cnt; $x++) { foreach ([...range(1, 48), ...range(114, 118)] as $number) { #echo "$number "; } } echo round(microtime(true)-$mc,4)."\n"; # ----------------------------------- echo "for loop\n"; $mc = microtime(true); for($x=0; $x<=$cnt; $x++) { for ($y=1; $y < 118; $y++) { if (($y>=1 && $y<=48) || ($y>=115 && $y <=117)) { #echo $y . " " ; } else { // do nothing } } } echo round(microtime(true)-$mc,4)."\n"; # ----------------------------------- function printRange(int $from, int $to) { for($i=$from; $i<=$to; $i++) { #echo "$i "; } } echo "function calls\n"; $mc = microtime(true); for($x=0; $x<=$cnt; $x++) { printRange(1, 48); printRange(114, 118); } echo round(microtime(true)-$mc,4)."\n";

preferences:
35.49 ms | 406 KiB | 5 Q