Jednak ostatnio trafiłem na artykuł http://phplens.com/lens/php-book/optimizin...bugging-php.php Zobaczcie, do czego tam doszli.
Cytat
Do References Speed Your Code?
References do not provide any performance benefits for non-object variables. For example, consider the following code:
[php:1:9bf200aba9]<?php
function TestRef(&$a)
{
$b = $a;
$c = $a;
}
$one = 1;
ProcessArrayRef($one);
?>[/php:1:9bf200aba9]
And the same code without references:
[php:1:9bf200aba9]<?php
function TestNoRef($a)
{
$b = $a;
$c = $a;
}
$one = 1;
ProcessArrayNoRef($one);
?>[/php:1:9bf200aba9]
php does not actually create duplicate variables when "pass by value" is used, but uses high speed reference counting internally. So in TestRef(), $b and $c take longer to set because the references have to be tracked, while in TestNoRef(), $b and $c just point to the original value of $a, and the reference counter is incremented. So TestNoRef() will execute faster than TestRef().
In contrast, functions that accept object parameters have a performance advantage when references are used. This is because objects do not use reference counting, so multiple copies of an object are created if "pass by value" is used. So the following code:
[php:1:9bf200aba9]<?php
function ObjRef(&$o)
{
$a =$o->name;
}
?>[/php:1:9bf200aba9]
is faster than:
[php:1:9bf200aba9]<?php
$function ObjRef($o)
{
$a = $o->name;
}
?>[/php:1:9bf200aba9]
Note: In php 5, all objects are passed by reference automatically, without the need of an explicit & in the parameter list.
References do not provide any performance benefits for non-object variables. For example, consider the following code:
[php:1:9bf200aba9]<?php
function TestRef(&$a)
{
$b = $a;
$c = $a;
}
$one = 1;
ProcessArrayRef($one);
?>[/php:1:9bf200aba9]
And the same code without references:
[php:1:9bf200aba9]<?php
function TestNoRef($a)
{
$b = $a;
$c = $a;
}
$one = 1;
ProcessArrayNoRef($one);
?>[/php:1:9bf200aba9]
php does not actually create duplicate variables when "pass by value" is used, but uses high speed reference counting internally. So in TestRef(), $b and $c take longer to set because the references have to be tracked, while in TestNoRef(), $b and $c just point to the original value of $a, and the reference counter is incremented. So TestNoRef() will execute faster than TestRef().
In contrast, functions that accept object parameters have a performance advantage when references are used. This is because objects do not use reference counting, so multiple copies of an object are created if "pass by value" is used. So the following code:
[php:1:9bf200aba9]<?php
function ObjRef(&$o)
{
$a =$o->name;
}
?>[/php:1:9bf200aba9]
is faster than:
[php:1:9bf200aba9]<?php
$function ObjRef($o)
{
$a = $o->name;
}
?>[/php:1:9bf200aba9]
Note: In php 5, all objects are passed by reference automatically, without the need of an explicit & in the parameter list.
Czyli wynikałoby z tego, że zazwyczaj (nie mówię o obiektach) referencje nie są konieczne. Jak to ma się do Waszych doświadczeń?