This is stone crazy!
Posted: Fri Aug 02, 2002 12:39 pm
Just as a note or perhaps a tip:
Iterating over arrays inside objects is roughly 2 to 3 times slower than iterating over local vars.
So....
is allways going to be slower than
Now the only problem is that if you have objects that need to iterate over an array, how do you get the array into the object or make the object somehow aware of the array without encpasulating that array into the object?
Well, according to something I stumbled across concerning the performance of PHP objects, there is such a thing as "True references".
Yeah, sure, the manual is my friend, but that's as long as it tells me everything (!) I need to know. I've been beating my head over this stuff all morning! Undocumented Hell is NOT a nice place to be.
Anyways, I hope this helps someone. Plus, I'd love to hear feedback on this.
BDKR
Iterating over arrays inside objects is roughly 2 to 3 times slower than iterating over local vars.
So....
Code: Select all
# Note that we are inside a class here
while($something==$something_else)
{ ++$this->array; }Code: Select all
while($something==$something_else)
{ ++$array; }Well, according to something I stumbled across concerning the performance of PHP objects, there is such a thing as "True references".
Great! The are some fantastic implications to this. BUT WHY ISN'T IT IN THE MANUAL!Hi,
I'm in the process of cleaning up the use of $this-> in my code.
However, as you know, I work with COM, and it is not a good idea to set a local variable to an object, and not freeing up and releasing objects will leak memory. Thankfully, PHP4 has a feature (new to version 4) that most other languages lack... true references.
Instead of your code:
$avar = $this->avar;
Just write:
$avar =& $this->avar;
This makes $avar a true reference, and (I believe) you should be able to work with $avar in loops without performance loss as it does not have to look up the $this.
Anyways, I hope this helps someone. Plus, I'd love to hear feedback on this.
BDKR