NYCPHP Meetup

NYPHP.org

[nycphp-talk] string function

tedd tedd at sperling.com
Thu Jul 3 13:45:33 EDT 2008


At 12:06 PM -0400 7/3/08, John Campbell wrote:
>On Thu, Jul 3, 2008 at 11:11 AM, Urb LeJeune <urb at e-government.com> wrote:
>>  Is this the same thing that you are trying to accomplish with the
>>  for loop?
>>
>>  Yes but increments (or decrements) are executed much more efficiently than
>>  additions.
>
>This is wrong for three reasons:
>1) 4 ++ increments is 2.5x slower than one increment by two.
>2) Unless you are using an opcode cache, any gains from faster
>execution are probably lost by the additional parsing required.  Of
>course this depends of the number of elements in the loop.
>3) Unreadable code is orders of magnitude more expensive than the
>performance benefit.
>
>Ignoring #3, the fastest way to write it is something like:
>
>$p = explode('|',$y);
>for($i=0,$c = count($p);$i<$c;) {
>echo $p[$i++],' ', $p[$i++], "<br>\n";
>}
>
>Removing the string concatenation is more beneficial than any
>increment / decrement hacking.




Geek fight!

I think that all the time spent debating this issue far exceeds the 
time actually saved between using one technique as compared to the 
other over the next 100+ years.

It's interesting to see what we get our collective shorts in a knot about.  :-)

Cheers,

tedd
-- 
-------
http://sperling.com  http://ancientstones.com  http://earthstones.com



More information about the talk mailing list