NYCPHP Meetup

NYPHP.org

[nycphp-talk] in and out redux

Dan Cech dcech at phpwerx.net
Tue Jan 27 18:01:33 EST 2004


Daniel Convissor wrote:
> Hi Folks:
> 
> I deleted the in and out thread, but something came up, so I'm starting a 
> new one...
> 
> The discussion on in and out wound up touching on using variables inside 
> strings.  The consensus was that the speed differential between using 
> variables inside and outside of strings was fixed.
> 
> Well, there's a current thread on internals at php.net, aka php-dev, in which
> Andrei says that using variables outside of quotes is faster:
> http://marc.theaimsgroup.com/?l=php-dev&m=107522145908795&w=2
> 
> Enjoy,
> 
> --Dan

The point is that there is a fixed overhead on every double-quoted 
string, being the time it takes to parse it and determine if it contains 
any variables.

I would guess that the procedure would then be something like:

1. split string into chunks (variable identifiers and sequences of 
characters)
3. replace variable chunks with the value of variables
4. put chunks back together

This is compared to the single quotes where you don't have to decide 
what is a variable and what is just character data.  Assuming the model 
above, it should be faster to use single-quotes, because you can 
eliminate step 1.

My guess would be that the 'fix' simply made step 1 more efficient.

All of this is purely my guess as to what is going on behind the scenes, 
I haven't actually looked at the source.  The remark in that thread:

'If you use a compiler cache like apc, this performance hit will be
totally removed as the optimizer compiles both representations into the
same format.'

Is probably fairly accurate, and would be great in a perfect world where 
everyone used caches...but in the real world it still appears that the 
single quotes method is faster.

Dan




More information about the talk mailing list