note 103894 added to function.end
| From: | hajikelist at gmail dot com | Date: | Mon, 09 May 2011 22:38:50 +0000 |
| Subject: | note 103894 added to function.end | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-179569@lists.php.net to get a copy of this message | ||
<?php
function getTime () {
list($usec, $sec) = explode(" ", microtime());
$time = ((float)$usec + (float)$sec);
return $time ;
} // * * *
$id = 'testindex';
$busters = array();
for ($a=0;$a<20000;$a++) {
$busters[$id.$a] = $id.$a. '_value';
}
//FASTEST
$start = getTime();
$last_entry = array_slice($busters, count($last_entry)-1); //last array key=>value entry
//now use array keys - far less wasteful
$buster = array_pop(array_keys($last_entry));
$end = getTime();
$total = $end - $start;
echo "Slice + Push Render time: " . $total;
echo "\r\n";
echo 'last key name:' .$buster ;
echo "\r\n";
//NEXT FASTEST
$start = getTime();
//wasteful looping is still more efficient than array_keys.
foreach($busters as $buster=>$keaton) {} //proportionally faster than array_pop+array_keys
$end = getTime();
$total = $end - $start;
echo 'For Each Render time: ' . $total;
echo "\r\n";
echo 'last key name:' .$buster ;
echo "\r\n";
echo 'The last key value is also set:' . $keaton;
echo "\r\n";
//SLOWEST
$start = getTime();
//wasteful creation of intermediary array_keys value [contains ALL array keys]
$buster = array_pop(array_keys($busters));
$end = getTime();
$total = $end - $start;
echo 'Array Keys Render time: ' . $total;
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/103894
Del: integrated -- https://master.php.net/note/delete/103894/integrated
Del: useless -- https://master.php.net/note/delete/103894/useless
Del: bad code -- https://master.php.net/note/delete/103894/bad+code
Del: spam -- https://master.php.net/note/delete/103894/spam
Del: non-english -- https://master.php.net/note/delete/103894/non-english
Del: in docs -- https://master.php.net/note/delete/103894/in+docs
Del: other reasons-- https://master.php.net/note/delete/103894
Reject -- https://master.php.net/note/reject/103894
Search -- https://master.php.net/manage/user-notes.php