I benched function with and without reference for a relatively large data
(512KB, I think).
I iterated 10,000 or 100,000 times to see the difference. (I posted the result
in this list)

The result is almost the same and should not be worried much about performance,
but function without reference was faster than with reference.

i.e.
function($data) vs. function(&$data)
function($data) was a little faster.

This is my guess (I'm not reading source code, so correct me if I'm wrong).
With reference, PHP need to additional work to make it as reference, since there
is &. While without reference, PHP only need to add symbol and increment
reference count for the variable.
I guess the additional work to make reference (&) makes function(&$date) a
little slower.

Anyway, I think it worth to know that Pass by value can make execution slower in
most languages, but not in PHP4. This is really good feature, because programmer
can only use pass by reference when they want change function parameter and
return the change to caller.
It makes a little easier to read PHP4 script.

Regards,
--
Yasuo Ohgaki

----- Original Message -----
From: "Neil Kimber" <[EMAIL PROTECTED]>
To: "Yasuo Ohgaki" <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>
Sent: Friday, March 30, 2001 6:51 PM
Subject: RE: [PHP] Passing by reference deprecated?


> I'm surprised. I would have thought that it would have been the other way
> around. Passing by reference should have similar implications to reference
> counting as used the Zend engine. It means that physical memory does not
> have to be allocated to passed variables (thereby saving resources in
> physical memory and time used in allocating and copying memory).
>
> In fact, because the Zend engine uses reference counting it will in effect
> use pass by reference for all parameters. In the case of a parameter passed
> as 'non-reference' it will only be allocated its own memory at a time that
> the parameter value is changed within the function. You can see a detailed
> explanation of how reference counting works here:
>
> http://www.zend.com/zend/art/ref-count.php
>
> I am not familiar with the parser source, so these are purely my thoughts on
> my understanding of the parser behaviour. I'd be interested to hear of other
> peoples views.
>
>
> -----Original Message-----
> From: Yasuo Ohgaki [mailto:[EMAIL PROTECTED]]
> Sent: 30 March 2001 10:08
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] Passing by reference deprecated?
>
>
> FYI
>
> Unless you need to modify and return modified contents of variables, pass by
> reference makes script execution a little slower under PHP4.
>
> --
> Yasuo Ohgaki
>
>
> ""Neil Kimber"" <[EMAIL PROTECTED]> wrote in message
> [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> > Pass by reference itself is not deprecated, just call-time
> > pass-by-reference.
> > I believe this means your calling line of code being prevented from
> > specifying that it should be invoked as pass-by-reference.
> >
> > So,
> >
> >
> > function NormalPassByRefence(&$prmValue)
> > {
> > $prmValue ++;
> > }
> >
> > $numValue=1;
> > NormalPassByRefence($numValue);  // This will still work
> > // $numValue =2 at this point
> >
> >
> > function CallTimePassByRefence($prmValue)
> > {
> > $prmValue ++;
> > }
> >
> > $numValue=1;
> > CallTimePassByRefence(&$numValue);  // This will no longer work - it's
> been
> > deprecated
> > // $numValue =1 at this point
> >
> >
> >
> >
> > -----Original Message-----
> > From: CC Zona [mailto:[EMAIL PROTECTED]]
> > Sent: 30 March 2001 04:40
> > To: [EMAIL PROTECTED]
> > Subject: [PHP] Passing by reference deprecated?
> >
> >
> > set_value(&$variable,$value)
> >    {
> >    $variable=value;
> >    }
> >
> > "Warning: Call-time pass-by-reference has been deprecated - argument
> passed
> > by value; If you would like to pass it by reference, modify the
> declaration
> > of [runtime function name](). If you would like to enable call-time
> > pass-by-reference, you can set allow_call_time_pass_reference to true in
> > your INI file. However, future versions may not support this any longer. "
> >
> > When did passing by reference get deprecated? The documentation at
> > <http://php.net/manual/en/language.references.pass.php> doesn't suggest
> > what to do instead--in fact, it uses an example like the syntax above.  So
> > my next question is: would using a return value or declaring a global be
> > the (only) other options?
> >
> > TIA
> >
> > --
> > CC
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: [EMAIL PROTECTED]
> >
> >
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: [EMAIL PROTECTED]
> >
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to