Re: More microptimisation (Was Re: [PHP] Variable as an index)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2008/12/22 Nathan Nobbe <quickshiftin@xxxxxxxxx>:
> On Mon, Dec 22, 2008 at 3:10 PM, Clancy <clancy_1@xxxxxxxxxxxx> wrote:
>
>> On Mon, 22 Dec 2008 10:20:09 +1100, dmagick@xxxxxxxxx (Chris) wrote:
>> ............
>> >I'd call this a micro-optimization. If changing this causes that much of
>> >a difference in your script, wow - you're way ahead of the rest of us.
>>
>> Schlossnagle (in "Advanced PHP Programming") advises:
>>
>> $i = 0; while ($i < $j)
>>        {
>>        ........
>>        ++$i;
>>        }
>>
>> rather than:
>>
>> $i = 0; while ($i < $j)
>>        {
>>        .......
>>        $i++;
>>        }
>>
>> as the former apparently uses less memory references.  However I find it
>> very hard to
>> believe that the difference would ever show up in the real world.
>
>
> nonsense, some college kid is going to put ++$i on a test to try an impress
> the professor when the semantics call for $i++ :D
>
> -nathan
> p.s.
> in case you couldnt tell; been there, done that. lol

Well, in all fairness, it *is* faster--but you'll only notice the
difference in extremely tight and long-running loops (try it ;) ). As
long as you know why you're using it and what the side effects are, it
would be fine. But as an optimization tool, I'd agree that it's pretty
much pointless.

It's good to remember the Rules of Optimization:

#1) Don't.
#2) (For experts only) Don't do it yet.


Torben

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux