note 113024 added to function.range

From: Date: Mon, 19 Aug 2013 21:48:36 +0000
Subject: note 113024 added to function.range
Groups: php.notes 
Request: Send a blank email to php-notes+get-196023@lists.php.net to get a copy of this message
I've been introduced with range() function not so long ago, and I found that examples about it is somewhat wrong, even inefficient: <?php $o = ""; $time_start = microtime(true); foreach(range(1, 10000) as $val) { $o .= $val; } $time_end = microtime(true); $time = $time_end - $time_start; echo 'rangein: '.$time.'<br />'; $o = ""; $time_start = microtime(true); $a = range(1, 10000); foreach($a as $val) { $o .= $val; } $time_end = microtime(true); $time = $time_end - $time_start; echo 'rangeout: '.$time.'<br />'; ?> Which gives results: rangein: 0.0025348663330078 rangeout: 0.0019199848175049 In some cases difference is even bigger and proportional to the range generated. I suppose that results of range() are cached/hashed. Note: execution order does affects execution times, but difference still exists ---- Server IP: 69.147.83.199 Probable Submitter: 95.180.61.112 ---- Manual Page -- http://php.net/manual/en/function.range.php Edit -- https://master.php.net/note/edit/113024 Del: integrated -- https://master.php.net/note/delete/113024/integrated Del: useless -- https://master.php.net/note/delete/113024/useless Del: bad code -- https://master.php.net/note/delete/113024/bad+code Del: spam -- https://master.php.net/note/delete/113024/spam Del: non-english -- https://master.php.net/note/delete/113024/non-english Del: in docs -- https://master.php.net/note/delete/113024/in+docs Del: other reasons-- https://master.php.net/note/delete/113024 Reject -- https://master.php.net/note/reject/113024 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#196023) next »