note 103855 added to function.end

From: Date: Fri, 06 May 2011 21:27:02 +0000
Subject: note 103855 added to function.end
Groups: php.notes 
Request: Send a blank email to php-notes+get-179508@lists.php.net to get a copy of this message
some notes on Tim C's method using foreach is far faster: For 2000 keys twice as fast, for 20,000 keys it takes 1/5 of the time as the array keys method... the more keys, the more benefit the foreach has. This could be due to the skipped action of building an intermediary set with array_keys [I believe arrays allocates new memory for all of the keys in the original array, which is unnecessary in this case.] test: <?php function getTime () { list($usec, $sec) = explode(" ", microtime()); $time = ((float)$usec + (float)$sec); return $time ; } // * * * $id = 'testindex'; $busters = array(); for ($a=0;$a<22000;$a++) { $busters[$id.$a] = $id.$a; } $start = getTime(); //using foreach foreach($busters as $buster=>$keaton) {} //get last element $end = getTime(); $total = $end - $start; echo "\r\n"; echo "For Each Render time: " . $total; echo "\r\n"; echo "\r\n"; $start = getTime(); //array pop / keys method $buster = array_pop(array_keys($busters)); $end = getTime(); $total = $end - $start; echo "\r\n"; echo "Array Keys Render time: " . $total; echo "\r\n"; echo "\r\n"; ---- Server IP: 69.147.83.197 Probable Submitter: 76.14.99.95 ---- Manual Page -- http://www.php.net/manual/en/function.end.php Edit -- https://master.php.net/note/edit/103855 Del: integrated -- https://master.php.net/note/delete/103855/integrated Del: useless -- https://master.php.net/note/delete/103855/useless Del: bad code -- https://master.php.net/note/delete/103855/bad+code Del: spam -- https://master.php.net/note/delete/103855/spam Del: non-english -- https://master.php.net/note/delete/103855/non-english Del: in docs -- https://master.php.net/note/delete/103855/in+docs Del: other reasons-- https://master.php.net/note/delete/103855 Reject -- https://master.php.net/note/reject/103855 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#179508) next »