NYCPHP Meetup

NYPHP.org

[nycphp-talk] string function

Kristina Anderson ka at kacomputerconsulting.com
Thu Jul 3 22:05:31 EDT 2008


If rewriting this function saves me .0001 milliseconds of processing 
time, can I spend that time watching baseball instead of writing code??

:) Kristina

> 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
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
> 
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
> 
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
> 
> 





More information about the talk mailing list