note 103894 deleted from function.end by danbrown

From: Date: Wed, 11 May 2011 15:50:15 +0000
Subject: note 103894 deleted from function.end by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-179637@lists.php.net to get a copy of this message
Note Submitter: hajikelist at gmail dot com ---- <?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($busters)-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"; ?>

« previous php.notes (#179637) next »