note 62531 added to language.references
| From: | Xor at osu1 dot php dot net | Date: | Thu, 02 Mar 2006 15:43:15 +0000 |
| Subject: | note 62531 added to language.references | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-104715@lists.php.net to get a copy of this message | ||
if given little - passing an array by reference slower than by value,
but not if it is necessary to process much data.
function test_ref(&$arr) {
$size = sizeof($arr);
for($n=0; $n<$size; $n++) {
$x .= $arr[$n];
}
return $x;
}
function test_val($arr) {
$size = sizeof($arr);
for($n=0; $n<$size; $n++) {
$x .= $arr[$n];
}
return $x;
}
// fill array
for($n=0; $n<500000; $n++) {
$ar[] = "test".$n;
}
$Bs = array_sum(explode(' ', microtime()));
test_ref($ar);
echo "<br />The function using a reference took ".(array_sum(explode(' ',
microtime()))-$Bs);
$Bs = array_sum(explode(' ', microtime()));
test_val($ar);
echo "<br />The funktion using a value took: ".(array_sum(explode(' ',
microtime()))-$Bs);
The function using a reference took 10.035583019257
The funktion using a value took: 10.531390190125
----
Server IP: 66.163.161.117
Probable Submitter: 195.131.23.140
----
X-Spam-Status: No, hits=3.3 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER,
HTML_MESSAGE autolearn=no version=2.64
----
Manual Page -- http://www.php.net/manual/en/language.references.php
Edit -- http://master.php.net/note/edit/62531
Del: integrated -- http://master.php.net/note/delete/62531/integrated
Del: useless -- http://master.php.net/note/delete/62531/useless
Del: bad code -- http://master.php.net/note/delete/62531/bad+code
Del: spam -- http://master.php.net/note/delete/62531/spam
Del: non-english -- http://master.php.net/note/delete/62531/non-english
Del: in docs -- http://master.php.net/note/delete/62531/in+docs
Del: other reasons-- http://master.php.net/note/delete/62531
Reject -- http://master.php.net/note/reject/62531
Search -- http://master.php.net/manage/user-notes.php