You are here: Re: Passing by reference better than returning a value when calling a function? « PHP Programming Language « IT news, forums, messages
Re: Passing by reference better than returning a value when calling a function?

Posted by ZeldorBlat on 10/28/07 22:49

On Oct 28, 2:25 pm, "duzhid...@gmail.com" <duzhid...@gmail.com> wrote:
> Hello:
>
> When I need a function to generate a string, I have two methods:
>
> 1.
> pass by reference:
>
> mystring = "";
> myfunction( mystring ); // prototype of myfunction( &anystring );
>
> OR 2.
> mystring = myfunction(); //which return a string
>
> According to experience of C/C++, the former one is better as of the
> efficient, how about PHP?
>
> Thanks.

In addition to what everyone else said (and they're both absolutely
correct) I tried both ways through a profiler. Assigning the return
value was about 40% faster than passing the reference.

So, to reiterate, do what makes sense, not what you /think/ will be
faster. If you run into performance problems later then you can
systematically optimize using a profiler or similar tool.

Google for "premature optimization" for more on the subject.

 

Navigation:

[Reply to this 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

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