note 111529 modified in function.range by danbrown

From: Date: Mon, 04 Mar 2013 17:43:44 +0000
Subject: note 111529 modified in function.range by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-193814@lists.php.net to get a copy of this message
for is better than range: <?php $time_start = microtime(true); foreach(range(1, 50000) as $val) { echo $val.','; } $time_end = microtime(true); $time = $time_end - $time_start; echo '<br /><br />'.$time.'<br /> <br />'; $time_start = microtime(true); for($i = 1; $i <= 50000; $i++) { echo $i.','; } $time_end = microtime(true); $time = $time_end - $time_start; echo '<br /><br />'.$time.'<br /> <br />'; ?> Range: 0.41276001930237 For: 0.3721399307251 --was-- for is better than range: $time_start = microtime(true); foreach(range(1, 50000) as $val) { echo $val.','; } $time_end = microtime(true); $time = $time_end - $time_start; echo '<br /><br />'.$time.'<br /> <br />'; $time_start = microtime(true); for($i = 1; $i <= 50000; $i++) { echo $i.','; } $time_end = microtime(true); $time = $time_end - $time_start; echo '<br /><br />'.$time.'<br /> <br />'; Range: 0.41276001930237 For: 0.3721399307251 http://php.net/manual/en/function.range.php

« previous php.notes (#193814) next »