note 30010 deleted from language.references.pass by sniper
| From: | sniper@php.net | Date: | Tue, 30 Sep 2003 01:24:36 +0000 |
| Subject: | note 30010 deleted from language.references.pass by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-57338@lists.php.net to get a copy of this message | ||
Note Submitter: phpdocs@regs.nebcorp.com
----
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.