note 30010 added to language.references.pass
| From: | phpdocs at regs dot nebcorp dot com | Date: | Tue, 04 Mar 2003 04:08:04 +0000 |
| Subject: | note 30010 added to language.references.pass | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-44809@lists.php.net to get a copy of this message | ||
Regarding the speed of passing via reference as opposed to passing (by default) via value:
Passing by reference will always be quicker, as the overhead of copying data around in memory will
*not* be incurred. Then why did the previous poster seem to see a 5% performance advantage in when
testing?
You'll note that the first test performed was the one using pass-by-reference, rather than the
pass by value. Had the order of the tests be reversed, I'm fairly certain the results would
have been reversed. Why?
Filesystem caching.
The slowest thing in the whole test would be the disk I/O to read the file itself. By the time the
second (pass-by-value) test is run, all the data has been cached in memory by the OS.
But regardless, speed is not the main reason to do pass by reference (unless you're dealing
with rather large data structures, in which case it will improve both speed and memory footprint).
The main reason is to be able to pass data structure around and manipulate them.
--
http://www.php.net/manual/en/language.references.pass.php
http://master.php.net/manage/user-notes.php?action=edit+30010
http://master.php.net/manage/user-notes.php?action=delete+30010
http://master.php.net/manage/user-notes.php?action=reject+30010