Reply to Re: string concat vs. join/implode

Your name:

Reply:


Posted by frugalprogrammer on 05/14/07 19:05

On May 14, 11:27 am, NoWhereMan <nowheremanNOS...@flashmailSPAM.com>
wrote:
> Maybe a stupid question.
>
> -------------------------
> 1
> -------------------------
> $str = '';
>
> for($i=0; $i<10; $i++)
> $str .= $i;
>
> echo $str;
>
> -------------------------
> 2
> -------------------------
> $str = array();
>
> for($i=0; $i<10; $i++)
> $str[]= $i;
>
> echo implode('', $str);
>
> -------------------------
>
> I suppose the latter will be more performant because there's less work for
> the garbage collector, am I right?
>
> thanks
>
> --
> NoWhereMan (e.v.)
> --http://www.nowhereland.it
> --http://flatpress.nowhereland.it

I would say probably not, as (1) is touching each element n times,
whereas (2) is most likely n*ln(n) in the best case. For i=10, it'll
double. implode() probably just runs your (1) again, appending each
element. I'm not entirely sure how the GC operates in PHP or what kind
of performance hit you might take, but it seems like copy-on-write
could make dereference in (1) not happen as often as you may think.

Regards,
Andrew

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация