note 87795 added to function.sizeof

From: Date: Mon, 22 Dec 2008 09:04:40 +0000
Subject: note 87795 added to function.sizeof
Groups: php.notes 
Request: Send a blank email to php-notes+get-148447@lists.php.net to get a copy of this message
Here are real test for below statements: Source: <?php $arr = array(); $num = 1000000; echo "Populating test array with $num elements ... "; for($i=0; $i<$num; $i++) { $arr[$i] = microtime(true) . mt_rand(); } echo "Populated.\n\n"; echo "Start testing FOREAH ... \n"; $start_time = microtime(true); foreach ($arr as $i=>$elem) { $res = isset($arr[$i]); } echo "FOREACH result: " . (microtime(true) - $start_time) . "\n\n"; echo "Start testing regular FOR ... \n"; $start_time = microtime(true); for ($i=0; $i<sizeof($arr); $i++) { $res = isset($arr[$i]); } echo "Regular for result: " . (microtime(true) - $start_time) . "\n\n"; echo "Starting test for pre-computed size array FOR ... \n"; $start_time = microtime(true); $sizeof_arr = sizeof($arr); for ($i=0; $i<$sizeof_arr; $i++) { $res = isset($arr[$i]); } echo "pre-computed size of array FOR: " . (microtime(true) - $start_time); ?> Output: emil@neon:~$ php test-loops-performance.php Populating test array with 1000000 elements ... Populated. Start testing FOREAH ... FOREACH result: 0.500122070312 Start testing regular FOR ... Regular for result: 0.886044979095 Starting test for pre-computed size array FOR ... pre-computed size of array FOR: 0.454435825348 ---- Server IP: 217.75.128.29 Probable Submitter: 85.91.139.97 ---- Manual Page -- http://www.php.net/manual/en/function.sizeof.php Edit -- https://master.php.net/note/edit/87795 Del: integrated -- https://master.php.net/note/delete/87795/integrated Del: useless -- https://master.php.net/note/delete/87795/useless Del: bad code -- https://master.php.net/note/delete/87795/bad+code Del: spam -- https://master.php.net/note/delete/87795/spam Del: non-english -- https://master.php.net/note/delete/87795/non-english Del: in docs -- https://master.php.net/note/delete/87795/in+docs Del: other reasons-- https://master.php.net/note/delete/87795 Reject -- https://master.php.net/note/reject/87795 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#148447) next »