note 60979 added to language.references
| From: | SlavaKudinov | Date: | Sun, 22 Jan 2006 10:01:54 +0000 |
| Subject: | note 60979 added to language.references | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-102233@lists.php.net to get a copy of this message | ||
In addition to the "array vs &array" example below, php 5.1.2. It seems passing an
array by reference slower than by value, consider:
<?php
function test_ref(&$arr) {
$size = sizeof($arr);
for($n=0; $n<$size; $n++) {
$x = 1;
}
}
function test_val($arr) {
$size = sizeof($arr);
for($n=0; $n<$size; $n++) {
$x = 1;
}
}
// fill array
for($n=0; $n<2000; $n++) {
$ar[] = "test".$n;
}
$time = microtime();
test_ref($ar);
echo "<br />The function using a reference took ".(microtime() - $time)."
s";
$time = microtime();
test_val($ar);
echo "<br />The funktion using a value took: ".(microtime() - $time)." s";
echo "<br />Done";
?>
output:
The function using a reference took 0.002694 s
The funktion using a value took: 0.000847 s
----
Server IP: 64.246.30.37
Probable Submitter: 82.209.219.140
----
Manual Page -- http://www.php.net/manual/en/language.references.php
Edit -- http://master.php.net/manage/user-notes.php?action=edit+60979
Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+60979&report=yes&reason=added+to+the+manual
Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+60979&report=yes&reason=bad+code
Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+60979&report=yes&reason=spam
Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+60979&report=yes&reason=useless
Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+60979&report=yes&reason=non-english
Delete: already in docs -- http://master.php.net/manage/user-notes.php?action=delete+60979&report=yes&reason=already+in+docs
Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+60979&report=yes
Reject -- http://master.php.net/manage/user-notes.php?action=reject+60979&report=yes
Search -- http://master.php.net/manage/user-notes.php