note 103314 added to function.array-filter
| From: | rmaslo at osu1 dot php dot net | Date: | Wed, 06 Apr 2011 23:49:48 +0000 |
| Subject: | note 103314 added to function.array-filter | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-178576@lists.php.net to get a copy of this message | ||
benchmark
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
function odd($var)
{
return($var & 1);
}
$maxarr=50000;
for ($i=0; $i<$maxarr; $i++ ) $bigarr[$i]=rand(0,999999);
$t1=microtime_float();
$x1 = array_filter($bigarr, "odd");
$t2=microtime_float();
foreach($bigarr as $k=>$v) if (odd($v)) $x3[]=$v;
$t3=microtime_float();
foreach($bigarr as $k=>$v) if ($v & 1) $x3[]=$v;
$t4=microtime_float();
for ($i=0; $i<$maxarr; $i++ ) if (odd($bigarr[$i])) $x4 = $bigarr[$i];
$t5=microtime_float();
for ($i=0; $i<$maxarr; $i++ ) if ($bigarr[$i] & 1) $x5 = $bigarr[$i];
$t6=microtime_float();
echo (($t2-$t1)*100).' .... array_filter <BR>';
echo (($t3-$t2)*100).' .... foreach + func<BR>';
echo (($t4-$t3)*100).' .... func in foreach<BR>';
echo (($t5-$t4)*100).' .... for + func<BR>';
echo (($t6-$t5)*100).' .... func in for<BR>';
-------------------
4.90231513977 .... array_filter
5.48429489136 .... foreach + func
2.20520496368 .... func in foreach
5.27548789978 .... for + func
1.67551040649 .... func in for
----
Server IP: 147.32.160.17
Probable Submitter: 178.17.2.163
----
Manual Page -- http://www.php.net/manual/en/function.array-filter.php
Edit -- https://master.php.net/note/edit/103314
Del: integrated -- https://master.php.net/note/delete/103314/integrated
Del: useless -- https://master.php.net/note/delete/103314/useless
Del: bad code -- https://master.php.net/note/delete/103314/bad+code
Del: spam -- https://master.php.net/note/delete/103314/spam
Del: non-english -- https://master.php.net/note/delete/103314/non-english
Del: in docs -- https://master.php.net/note/delete/103314/in+docs
Del: other reasons-- https://master.php.net/note/delete/103314
Reject -- https://master.php.net/note/reject/103314
Search -- https://master.php.net/manage/user-notes.php